[php-src] Issue #13082: imagefontwidth and imagefontheight fail on valid GDFont

From: Date: Sat, 06 Jan 2024 10:47:07 +0000
Subject: [php-src] Issue #13082: imagefontwidth and imagefontheight fail on valid GDFont
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246184@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/13082 Author: jonaskohl ### Description The following code: ```php <?php const FONT_BUILTIN = 5; const FONT_EXTERNAL = __DIR__ . "/MiscTT_12x20_LE.gdf"; // Uncomment to download sample font: // copy("http://www.danceswithferrets.org/lab/gdfs/MiscTT_12x20_LE.gdf", FONT_EXTERNAL); // Note: This is just a sample font. This problem occurs with every valid gdf file. echo strval(imagefontwidth(FONT_BUILTIN)) . PHP_EOL; echo strval(imagefontheight(FONT_BUILTIN)) . PHP_EOL; $font = imageloadfont(FONT_EXTERNAL); if ($font === false) die("Failed to load font" . PHP_EOL); if (!($font instanceof GdFont)) die("Font is not of type " . GdFont::class . PHP_EOL); var_dump($font); $fontWidth = imagefontwidth($font); $fontHeight = imagefontheight($font); echo strval($fontWidth) . PHP_EOL; echo strval($fontHeight) . PHP_EOL; ``` Resulted in this output: ``` 9 15 object(GdFont)#1 (0) { } PHP Fatal error: Uncaught TypeError: imagefontwidth(): Argument #1 ($font) must be of type GdFont|int, GdFont given in /Users/jonas/Desktop/sample.php:19 Stack trace: #0 /Users/jonas/Desktop/sample.php(19): imagefontwidth(Object(GdFont)) #1 {main} thrown in /Users/jonas/Desktop/sample.php on line 19 Fatal error: Uncaught TypeError: imagefontwidth(): Argument #1 ($font) must be of type GdFont|int, GdFont given in /Users/jonas/Desktop/sample.php:19 Stack trace: #0 /Users/jonas/Desktop/sample.php(19): imagefontwidth(Object(GdFont)) #1 {main} thrown in /Users/jonas/Desktop/sample.php on line 19 ``` But I expected this output instead: ``` 9 15 object(GdFont)#1 (0) { } 12 20 ``` ### PHP Version 8.3.1 ### Operating System macOS 14.2.1

« previous php.bugs (#246184) next »