473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

GD, IMagick and Chinese words in utf-8

Hi,
I have a problem with Chinese words coded in utf-8. I need to display
Chinese marks/words with use of GD or IMagick libs.

Chinese text that I need to display is written as plain text in .txt
file. I'm not pasting that text inside code. When I'm using only read
and echo in PHP. Everything looks fine:

example:
<?php
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<?php
echo file_get_contents('text/3400-343A.txt');
?>
</body>
</html>

Result of that script is correctly displayed text.

Problems starts when I need to display that marks in GD
example:
<?php
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
$image->newImage(800, 75, $pixel);
$pixel->setColor('black');
$text = file_get_contents('text/5FB4-5FFA.txt');
//$draw->setFont('fonts/ch.ttf');
$draw->setFontSize( 30 );
$image->annotateImage($draw, 10, 45, 0, $text);
$image->setImageFormat('png');
header ('Content-type: image/png; charset=utf-8');
echo $image;
?>

Only one thing that I'm getting are "?" marks. That font is some
Chinese font in ttf, doesn't work with and without it. Quite the same
problem appears when I try to use IMagick lib.

<?php
header('Content-type: image/png; charset=utf-8');
$im = imagecreatetruecolor(400, 20);
$white = imagecolorallocate($im, 238, 238, 238);
$black = imagecolorallocate($im, 21, 21, 21);
imagefilledrectangle($im, 0, 0, 399, 29, $black);
$text = file_get_contents('text/3400-343A.txt');
$font = 'fonts/ch.ttf';
imagettftext($im, 14, 0, 10, 16, $white, $font, $text);
imagepng($im);
imagedestroy($im);
?>

I'm using here the same font, and I have the same result. Only "?"
marks.
Any ideas. Where I lose my self?

Seba
Jun 2 '08 #1
4 4727
Se**************@gmail.com a écrit :
$font = 'fonts/ch.ttf';
According to the name, I would say this font is specific to chinese,
still I'm asking : does it really supports chinese characters ?
Maybe the font is the problem, not truetype, or not complete... Just a
basic idea I propose.

Regards,
--
Guillaume
Jun 2 '08 #2

Guillaume, great TIP.
Fonts were Chinese but that what I want display was over the scope of
my current fonts.

I've downloaded Chinese fonts from http://www.wazu.jp/gallery/Fonts_Chi...aditional.html.

Thanks
Seba

Jun 2 '08 #3

Guillaume, great TIP.
Fonts were Chinese but that what I want display was over the scope of
my current fonts.

I've downloaded Chinese fonts from http://www.wazu.jp/gallery/Fonts_Chi...aditional.html.

Thanks
Seba

Jun 2 '08 #4
On May 30, 9:33 pm, Sebastian.Paw...@gmail.com wrote:
Hi,
I have a problem with Chinese words coded in utf-8. I need to display
Chinese marks/words with use of GD or IMagick libs.

Chinese text that I need to display is written as plain text in .txt
file. I'm not pasting that text inside code. When I'm using only read
and echo in PHP. Everything looks fine:

example:
<?php
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<?php
echo file_get_contents('text/3400-343A.txt');
?>
</body>
</html>

Result of that script is correctly displayed text.

Problems starts when I need to display that marks in GD
example:
<?php
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
$image->newImage(800, 75, $pixel);
$pixel->setColor('black');
$text = file_get_contents('text/5FB4-5FFA.txt');
//$draw->setFont('fonts/ch.ttf');
$draw->setFontSize( 30 );
$image->annotateImage($draw, 10, 45, 0, $text);
$image->setImageFormat('png');
header ('Content-type: image/png; charset=utf-8');
echo $image;
?>

Only one thing that I'm getting are "?" marks. That font is some
Chinese font in ttf, doesn't work with and without it. Quite the same
problem appears when I try to use IMagick lib.

<?php
header('Content-type: image/png; charset=utf-8');
$im = imagecreatetruecolor(400, 20);
$white = imagecolorallocate($im, 238, 238, 238);
$black = imagecolorallocate($im, 21, 21, 21);
imagefilledrectangle($im, 0, 0, 399, 29, $black);
$text = file_get_contents('text/3400-343A.txt');
$font = 'fonts/ch.ttf';
imagettftext($im, 14, 0, 10, 16, $white, $font, $text);
imagepng($im);
imagedestroy($im);
?>

I'm using here the same font, and I have the same result. Only "?"
marks.
Any ideas. Where I lose my self?

Seba
is your browser/OS support display chinese font?
Jun 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff | last post by:
Having a problem displaying both german and chinese characters from a UTF-8 database on the same *.jsp page. Can make Chinese characters appear correctly by including the following lines: <%@...
1
by: Anthony Liu | last post by:
The following 4 lines of code parses an XML document very well if the XML document contains only English words. But when I insert one Chinese character into the XML document, then Python starts...
4
by: Knackeback | last post by:
Hi, I wrote a XML file with GNU emacs 21.2.2 and with chinese character content encoded in UTF-8. I wrote something like: <?xml version="1.0" encoding="UTF-8"?> <test> <chinese>¼»</chinese>...
8
by: Agnes | last post by:
In my .net ,i need to generate an xml file , however, user may input a chinese character, Then , the xml will got something unknow characters. the following is my code, Does anyone know how to...
0
by: Alex Chan | last post by:
Hi group, I am writing a RFC Server with SAP.NET Connector to connect to SAP. There are chinese characters passing back and forth. I found that all chinese characters sending from SAP are...
4
by: K | last post by:
I've an XML file in UTF-8. It contains some chinese characters ( both simplified chinese and traditional chinese). In loading the XML file with MSXML parser, I used the below code to retrieve...
3
by: Tom | last post by:
Hi, I built a aspx web page which the charset is UTF-8. I need to present the same Chinese content to both Traditional and Simplified Chinese. However, it shows error code for UTF-8, Big 5 or...
2
by: Wassy | last post by:
Hi, i have a website which contains both chinese and english content which is stored in a database. Each record in the dB has an english and Chinese field. If a user enters a search string i have...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.