Bug #42218 [Com]: ImageTTFBBox & any2eucjp

From: Date: Tue, 22 Nov 2022 11:35:00 +0000
Subject: Bug #42218 [Com]: ImageTTFBBox & any2eucjp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242870@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=42218&edit=1

 ID:                 42218
 Comment by:         himself at claus-justus-heine dot de
 Reported by:        fernando at barnatech dot com
 Summary:            ImageTTFBBox & any2eucjp
 Status:             No Feedback
 Type:               Bug
 Package:            GD related
 Operating System:   Suse 10.2
 PHP Version:        5.2.4RC1
 Assigned To:        pajoye
 Block user comment: N
 Private report:     N

 New Comment:

Have this same issue with PHP 8.0.25 (cli) (built: Nov 20 2022 23:13:38) ( ZTS )

Test case is with "standard aria" and Unicode char ✔

According to

http color slash slash
zuga.net/articles/unicode-all-characters-supported-by-the-font-arial-unicode-ms/

this should be supported by Arial (but ok ...)

Example script which triggers the error:

<?php
$fontFile = '/usr/share/fonts/corefonts/arial.ttf';
$text = '✔';
$textBox = imagettfbbox(10.0, 0, $fontFile, $text);


Previous Comments:
------------------------------------------------------------------------
[2015-03-22 13:24:40] web at koenige dot org

Somehow, my last response did not get posted. I wrote on 2015-02-23 11:36 UTC that the error message
disappeared with the new font. This was wrong. It is still there.

------------------------------------------------------------------------
[2015-02-23 11:36:55] web at koenige dot org

Indeed, the error message goes away. Probably because there are corresponding Japanese glyphs in the
mplus font. But the problem persists: The given string is UTF-8 but ImageTTFBBox() does not treat it
as UTF-8 but some JIS encoding. (And this only happens if GD library is compiled with JIS-mapped
Japanese Font Support.)

If I draw a diagram with the mplus font, I can see the Japanese symbols. I'd rather expect a
simple ndash (–) and the Euro sign (€) in the diagram, no Japanese characters.

------------------------------------------------------------------------
[2015-02-23 11:08:39] yohgaki@php.net

I think you have problem with font file. Try mplus to see if it works.

------------------------------------------------------------------------
[2015-02-23 10:29:28] web at koenige dot org

I can reproduce an error on PHP 5.5.21 (Further information at <http://phpinfo.bplaced.net/>, GD 2.1.0, Freetype 2.5.0
with JIS-mapped Japanese Font Support enabled. I cannot reproduce it on a system with PHP 5.5.21, GD
2.1.0, Freetype 2.5.5 and no JIS-mapped Japanese Font Support.

    ini_set("mbstring.internal_encoding", "UTF-8");

has no effect. File is encoded as UTF-8 without BOM (with BOM makes no difference).

Code:

<?php

    $box = imagettfbbox(12, 90, 'artichow/font/Tuffy.ttf', '– km €');

    $box = imagettfbbox(12, 90, 'artichow/font/Tuffy.ttf', '– €');

    $box = imagettfbbox(12, 90, 'artichow/font/Tuffy.ttf', 'km €');

?>

For the first two commands, I get

Warning: imagettfbbox() [function.imagettfbbox]: any2eucjp(): invalid code in input string in
/test.php on line n

The last command seems to be fine.

It looks like imagettfbbox() tries to determine the character encoding for the string (instead of
accepting it as UTF-8) and thinks for some reason it might be some Japanese encoding.

------------------------------------------------------------------------
[2014-07-16 04:23:53] yohgaki@php.net

Simply use UTF-8 for text. Following code works.
(Make sure you have Japanese font installed or use proper font/text)

<?php
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

imagefilledrectangle($im, 0, 0, 299, 299, $white);

$font = '/usr/share/fonts/mplus/mplus-2c-regular.ttf';

$bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion());

$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;

imagettftext($im, 10, 45, $x, $y, $black, $font, '日本語 Powered by PHP ' .
phpversion());

$bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version());

$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;

imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_version());

header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=42218


--
Edit this bug report at https://bugs.php.net/bug.php?id=42218&edit=1


Thread (24 messages)

« previous php.bugs (#242870) next »