[php-src] Issue #8001: imageftbbox returns too small bounding box

From: Date: Wed, 26 Jan 2022 01:21:35 +0000
Subject: [php-src] Issue #8001: imageftbbox returns too small bounding box
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239289@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8001 Author: mirabilos ### Description The following code: ```php <?php $text = "2020-12-23T13:25:44Z"; $font = "./Inconsolatazi4varl_qu-Regular.otf"; // attached $fontsize = 14; $bbox = imageftbbox($fontsize, 0, $font, $text); $ascender = abs($bbox[7]) /* +1 */; $descender = abs($bbox[1]); $size_w = abs($bbox[0]) + abs($bbox[2]); $size_h = $ascender + $descender; $x = -$bbox[0]; $y = $ascender; $im = imagecreatetruecolor($size_w, $size_h); $bgcol = imagecolorallocate($im, 0xDD, 0xDD, 0xDD); $fgcol = imagecolorallocate($im, 0x00, 0x00, 0x23); imagefilledrectangle($im, 0, 0, $size_w - 1, $size_h - 1, $bgcol); imagefttext($im, $fontsize, 0, $x, $y, $fgcol, $font, $text); imagetruecolortopalette($im, FALSE, 256); if (0) { imagepng($im, NULL, 9); } else { print_r(array( "bbox" => $bbox, "ascender" => $ascender, "descender" => $descender, "size_w" => $size_w, "size_h" => $size_h, "x" => $x, "y" => $y, )); } ``` Resulted in this output: ``` Array ( [bbox] => Array ( [0] => 1 [1] => 0 [2] => 185 [3] => 0 [4] => 185 [5] => -11 [6] => 1 [7] => -11 ) [ascender] => 11 [descender] => 0 [size_w] => 186 [size_h] => 11 [x] => -1 [y] => 11 ) ``` But I expected this output instead: ``` Array ( [bbox] => Array ( [0] => 0 [1] => 1 [2] => 187 [3] => 1 [4] => 187 [5] => -13 [6] => 0 [7] => -13 ) [ascender] => 13 [descender] => 1 [size_w] => 187 [size_h] => 14 [x] => 0 [y] => 13 ) ``` The expected output is actually the one I get from php7.3-gd (7.3.19-1~deb10u1) on buster/i386 whereas the broken output (some values are too small) can be got from PHP 7.4, 8.0, 8.1 on various Debians. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980759 for the original downstream bugreport. ### PHP Version 7.4.11, 8.0.1, 8.1.0, probably any > 7.3 ### Operating System Debian

« previous php.bugs (#239289) next »