Bug #42218 [NoF]: ImageTTFBBox & any2eucjp

From: Date: Mon, 23 Feb 2015 11:08:40 +0000
Subject: Bug #42218 [NoF]: ImageTTFBBox & any2eucjp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190908@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
 Updated by:         yohgaki@php.net
 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:

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


Previous Comments:
------------------------------------------------------------------------
[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".

------------------------------------------------------------------------
[2007-10-03 18:36:08] super at superduper dot org

Hey! 

I'm sorry, i always found compiling the php module with all the dependencies a pain, which is
why I'm using Xampp. 

I'm being pretty busy at the moment and don't have time for setting up the build
environment and testing it out. As I said - I got around the issue by using ini_set( ... ) with
mbstring compiled in on two different servers (with and without jis comiled into gd).

Maybe there is someone who test compiles php everyday that could try it out with the different
settings. 

If you would like to have the code used for testing please let me know.

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


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