55namespace Intervention \Image \Drivers \Gd \Modifiers ;
66
77use Intervention \Image \Exceptions \ColorException ;
8+ use Intervention \Image \Exceptions \FontException ;
89use Intervention \Image \Exceptions \RuntimeException ;
910use Intervention \Image \Interfaces \ImageInterface ;
1011use Intervention \Image \Interfaces \SpecializedInterface ;
@@ -26,32 +27,40 @@ public function apply(ImageInterface $image): ImageInterface
2627 $ textColor = $ this ->gdTextColor ($ image );
2728 $ strokeColor = $ this ->gdStrokeColor ($ image );
2829
30+ // build full path to font file to make sure to pass absolute path to imageftbbox()
31+ // because of issues with different GD version behaving differently when passing
32+ // relative paths to imagettftext()
33+ $ fontPath = $ this ->font ->hasFilename () ? realpath ($ this ->font ->filename ()) : false ;
34+ if ($ this ->font ->hasFilename () && $ fontPath === false ) {
35+ throw new FontException ('Font file ' . $ this ->font ->filename () . ' does not exist. ' );
36+ }
37+
2938 foreach ($ image as $ frame ) {
3039 imagealphablending ($ frame ->native (), true );
3140 if ($ this ->font ->hasFilename ()) {
3241 foreach ($ lines as $ line ) {
3342 foreach ($ this ->strokeOffsets ($ this ->font ) as $ offset ) {
3443 imagettftext (
35- $ frame ->native (),
36- $ fontProcessor ->nativeFontSize ($ this ->font ),
37- $ this ->font ->angle () * -1 ,
38- $ line ->position ()->x () + $ offset ->x (),
39- $ line ->position ()->y () + $ offset ->y (),
40- $ strokeColor ,
41- $ this -> font -> filename () ,
42- (string ) $ line
44+ image: $ frame ->native (),
45+ size: $ fontProcessor ->nativeFontSize ($ this ->font ),
46+ angle: $ this ->font ->angle () * -1 ,
47+ x: $ line ->position ()->x () + $ offset ->x (),
48+ y: $ line ->position ()->y () + $ offset ->y (),
49+ color: $ strokeColor ,
50+ font_filename: $ fontPath ,
51+ text: (string ) $ line
4352 );
4453 }
4554
4655 imagettftext (
47- $ frame ->native (),
48- $ fontProcessor ->nativeFontSize ($ this ->font ),
49- $ this ->font ->angle () * -1 ,
50- $ line ->position ()->x (),
51- $ line ->position ()->y (),
52- $ textColor ,
53- $ this -> font -> filename () ,
54- (string ) $ line
56+ image: $ frame ->native (),
57+ size: $ fontProcessor ->nativeFontSize ($ this ->font ),
58+ angle: $ this ->font ->angle () * -1 ,
59+ x: $ line ->position ()->x (),
60+ y: $ line ->position ()->y (),
61+ color: $ textColor ,
62+ font_filename: $ fontPath ,
63+ text: (string ) $ line
5564 );
5665 }
5766 } else {
0 commit comments