Bug #42218 [Com]: ImageTTFBBox & any2eucjp

From: Date: Sun, 22 Mar 2015 13:24:42 +0000
Subject: Bug #42218 [Com]: ImageTTFBBox & any2eucjp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191525@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:         web at koenige dot org
 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:

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.


Previous Comments:
------------------------------------------------------------------------
[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);

------------------------------------------------------------------------
[2014-07-16 03:11:45] shenkong at qq dot com

same problem.
Warning: imagettfbbox(): any2eucjp(): invalid code in input string in
/media/psf/pf/lib/ImageChart/LineChart.class.php on line 551

os:centos 7
file encoding:utf-8
text:标题 in chinese
font:msyh.ttf (Microsoft YaHei)
phpver:5.5.14
extver:
curl-7.37.0.tar.gz
freetype-2.5.3.tar.bz2
jpegsrc.v9a.tar.gz
libevent-2.0.21-stable.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.6.12.tar.gz
libxml2-2.6.30.tar.gz
libxslt-1.1.22.tar.gz
php-5.5.14.tar.bz2
zlib-1.2.8.tar.gz

phpconfig:
'./configure' '--prefix=/usr/local/services/php' '--enable-fpm'
'--with-mysql=mysqlnd' '--with-mysqli=mysqlnd'
'--with-config-file-path=/usr/local/services/php/etc' '--with-gd'
'--enable-gd-native-ttf' '--enable-gd-jis-conv'
'--with-freetype-dir=/usr/local/services/plugin/freetype/'
'--with-jpeg-dir=/usr/local/services/plugin/jpeg/'
'--with-png-dir=/usr/local/services/plugin/libpng/'
'--with-zlib-dir=/usr/local/services/plugin/zlib/' '--enable-xml'
'--enable-mbstring' '--enable-soap'
'--with-libxml-dir=/usr/local/services/plugin/libxml/'
'--with-xsl=/usr/local/services/plugin/libxslt/'
'--with-curl=/usr/local/services/plugin/curl/'
'--with-mcrypt=/usr/local/services/plugin/libmcrypt/' '--enable-sysvsem'
'--enable-sysvshm' '--enable-sysvmsg'
'--with-iconv-dir=/usr/local/services/plugin/libiconv/' '--enable-sockets'

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


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 (#191525) next »