PHP imagettftext

nietaL

NGBler
Registriert
8 Sep. 2013
Beiträge
231
Ort
Exilgullianer
Hey Leute,

mein Skript schafft es einfach nicht, die Schriftart zu laden:

[src=php]
// Definition des Dateityps
header('Content-type: image/jpeg');

// Quellbild
$jpg = imagecreatefromjpeg('hg_west.jpg');

// Textfarbe
$white = imagecolorallocate($jpg, 255, 255, 255);

// Definition der Schriftart mit einer ttf
$font = 'arial.ttf';

// Text aus der URL nehmen
$text = "test";

// Text auf das Bild setzen. Quellbild, Schriftgröße, Rotieren, X, Y, Farbe, Schriftart, Text
imagettftext($jpg, 50, 0, 20, 20, $white, $font, $text);

// Bild an Browser übergeben
imagejpeg($jpg);

// Cache löschen
imagedestroy($jpg);

[/src]


[03-Nov-2018 12:54:03 UTC] PHP Warning: imagettftext(): open_basedir restriction in effect. File(/arial.ttf) is not within the allowed path(s): (C:/Inetpub/vhosts/isleofmine.de\;C:\Windows\Temp\) in C:\Inetpub\vhosts\isleofmine.de\httpdocs\webgui\missions\picture\test2.php on line 22
[03-Nov-2018 12:54:03 UTC] PHP Warning: imagettftext(): Invalid font filename in C:\Inetpub\vhosts\isleofmine.de\httpdocs\webgui\missions\picture\test2.php on line 22



[src=php]// Definition des Dateityps
header('Content-type: image/jpeg');

// Quellbild
$jpg = imagecreatefromjpeg('hg_west.jpg');

// Textfarbe
$white = imagecolorallocate($jpg, 255, 255, 255);

// Definition der Schriftart mit einer ttf
$font = '/arial.ttf';

// Text aus der URL nehmen
$text = "test";

// Text auf das Bild setzen. Quellbild, Schriftgröße, Rotieren, X, Y, Farbe, Schriftart, Text
imagettftext($jpg, 50, 0, 20, 20, $white, $font, $text);

// Bild an Browser übergeben
imagejpeg($jpg);

// Cache löschen
imagedestroy($jpg);
[/src]

[03-Nov-2018 12:54:40 UTC] PHP Warning: imagettftext(): Could not find/open font in C:\Inetpub\vhosts\isleofmine.de\httpdocs\webgui\missions\picture\test2.php on line 22

Die Schriftart liegt im selben Ordner wie das Skript. Wie muss ich den Pfad denn schreiben?

Die gd image extension ist geladen, merging funktioniert einwandfrei.
 
Zuletzt bearbeitet:
  • Thread Starter Thread Starter
  • #3
[src=php]
<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>
[/src]

Das war's. Ich danke dir!
 
Zurück
Oben