Skip to content

Commit 76e96d3

Browse files
committed
Fix issue with GD and relative font paths
This patch builds full path to a font file with GD driver to make sure to pass absolute path to imageftbbox(). This is because of issues with different GD versions behaving differently when passing relative paths to imageftbbox()
1 parent 2c98def commit 76e96d3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Drivers/Gd/FontProcessor.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Intervention\Image\Drivers\Gd;
66

77
use Intervention\Image\Drivers\AbstractFontProcessor;
8+
use Intervention\Image\Exceptions\FontException;
89
use Intervention\Image\Geometry\Point;
910
use Intervention\Image\Geometry\Rectangle;
1011
use Intervention\Image\Interfaces\FontInterface;
@@ -36,12 +37,20 @@ public function boxSize(string $text, FontInterface $font): SizeInterface
3637
return $box;
3738
}
3839

40+
// build full path to font file to make sure to pass absolute path to imageftbbox()
41+
// because of issues with different GD version behaving differently when passing
42+
// relative paths to imageftbbox()
43+
$fontPath = realpath($font->filename());
44+
if ($fontPath === false) {
45+
throw new FontException('Font file ' . $font->filename() . ' does not exist.');
46+
}
47+
3948
// calculate box size from ttf font file with angle 0
4049
$box = imageftbbox(
4150
size: $this->nativeFontSize($font),
4251
angle: 0,
43-
font_filename: $font->filename(),
44-
string: $text
52+
font_filename: $fontPath,
53+
string: $text,
4554
);
4655

4756
// build size from points

0 commit comments

Comments
 (0)