imageftbbox returns too small bounding box
Description
The following code:
<?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
Please check the libgd version you are using (e.g. echo gd_info("GD Version")). I assume it is not the bundled libgd, so this would be an upstream issue from our side as well.
Huh, indeed. Installing php7.3-{cli,gd} on bullseye (after removing the Breaks from php-common the maintainer added just to make it harder to coinstall the versions) yields the same broken values…
$ php7.3 x.php |fgrep scender
[ascender] => 11
[descender] => 0
… while LD_PRELOADing the exact library from buster libgd3_2.2.5-5.2_amd64.deb, ceteris paribus, gives the correct values:
$ LD_PRELOAD=$PWD/libgd.so.3.0.5 php7.3 x.php |fgrep scender
[ascender] => 13
[descender] => 1
$ LD_PRELOAD=$PWD/libgd.so.3.0.5 php7.4 x.php |fgrep scender
[ascender] => 13
[descender] => 1
This makes it 100% clear that libgd3 is at fault. I reported this as https://github.com/libgd/libgd/issues/814 and will reassign the Debian bug.
(Now, if the PHP maintainers in Debian had done their duty, this could have been resolved much earlier…)
@mirabilos what is the reason to close this one? is it solved?
@pierrejoye, this is likely an upstream (libgd) issue. I haven't checked, but the bundled libgd might not be affected.
Pierre Joye dixit:
@.*** what is the reason to close this one? is it solved?
It’s proven to depend only on the libgd3.so.* binary file, so PHP, Freetype, etc. are provably excluded from possibly being the issue.
bye, //mirabilos
[00:02]
danke
Sehe bitte die frage in libgd ticket :)
On Sun, Jan 30, 2022, 10:03 PM mirabilos @.***> wrote:
Pierre Joye dixit:
@.*** what is the reason to close this one? is it solved?
It’s proven to depend only on the libgd3.so.* binary file, so PHP, Freetype, etc. are provably excluded from possibly being the issue.
bye, //mirabilos
[00:02]
gecko: benutzt du emacs ? [00:03] nö [00:03] nur n normalen mac [00:04] argl [00:04] ne den editor -- Vutral und gecko2 in #deutsch (NB: Editor? Betriebssystem.) — Reply to this email directly, view it on GitHub https://github.com/php/php-src/issues/8001#issuecomment-1025162037, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACE6KAS52JCBQBZUDDATS3UYVHNLANCNFSM5MZY5N7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>