tags:

views:

55

answers:

2

Finally I had to recompile PHP with --enable-gd-jis-conv. However the text display is wrong, in Japanese.

$text = '夏の天気';
$fontfile = '/usr/share/fonts/japanese/TrueType/sazanami-mincho.ttf';

return imagettftext ($image, $size,  $angle,  $x,  $y,  $color, $fontfile, $text);

But different kanji (Japanese characters) are displayed instead (very different, looks like Chinese).

Could it be an encoding issue?

Using PHP 5.3.3 on RHEL 5.4.

+1  A: 

Well, japanese as a multibyte encoded language has quite a few quirks. First of all, be sure that your server has the mbstring module installed.

Second, to reduce the chances of possible breakage midway, try to keep all encodings in your site/project consistent: site views and source files should ideally be written with the same encoding.

Specifically for your problem, you might want to try using the following functions:

mb_http_input http://www.php.net/manual/en/function.mb-http-input.php

This one will make sure your HTTP input is correctly encoded (ie. form data).

mb_ internal_ encoding http://www.php.net/manual/en/function.mb-internal-encoding.php

Sets the internal encoding used by PHP.

mb_regex_encoding http://www.php.net/manual/en/function.mb-regex-encoding.php

Sets the encoding used by PHP for regexes.

mb_convert_encoding http://www.php.net/manual/en/function.mb-convert-encoding.php

For String conversion.

mb_convert_variables http://www.php.net/manual/en/function.mb-convert-variables.php

Converts encodings of a whole batch of strings/arrays.

Edit: besides, from the name of the module, you might want to try feeding JIS encoded data to the function.

Guillaume Bodi
In order to focus on *gd* tests and avoid some other side-effects, the text is currently entered directly in the php code (夏の天気). The `mb_internal_coding('utf-8')` is set at the beginning. There must be something simple missing - maybe the font is wrong? (on a RHEL English system, `yum install fonts-japanese`).
ring0
Thanks for your contribution (voted up)
ring0
A: 

I had to run this to get it to work

$text = mb_convert_encoding('夏の天気', "SJIS", 'UTF-8');
ring0