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:
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.
Previous Comments:
------------------------------------------------------------------------
[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'
------------------------------------------------------------------------
[2007-10-11 01:00:00] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
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