Page 1 of 1

Encoding problems

Posted: 2008-08-12T03:24:39-07:00
by AppleAp
Hello,

I'm using ImageMagick on few my websites and I just love the quality of IM and power, it's much higher than GD's quality.

But when I tried to insert text into images, I met one problem. I have this TTF font:
http://rapidshare.com/files/136740441/visitor1.ttf.html

Which has both English and Russian letters. Russian works fine with Photoshop and other software.

I'm trying to do this:

Code: Select all

<?PHP
error_reporting(E_ALL);
system ("/usr/local/bin/convert /home/ayva/c/a.png -font /home/ayva/c/visitor1.ttf -gravity \"Center\" -draw \"text 0,0 'А Вот И Полли'\" /home/ayva/c/textimage.png");
print "Картинка создана";
?>
I'm running this PHP script on my Linux (Fedora 6) dedicated server.

But I get "? ??? ? ?????" instead of "А Вот И Полли".

I've tried to add -encoding Unicode to the line, but I get same result.

I wonder how can I fix this?

Re: Encoding problems

Posted: 2008-08-12T05:03:20-07:00
by Bonzo
Try -annotate instead of draw.

Code: Select all

<?PHP
error_reporting(E_ALL);
system ("/usr/local/bin/convert /home/ayva/c/a.png -font /home/ayva/c/visitor1.ttf -gravity \"Center\" -annotate +0+0 'А Вот И Полли' /home/ayva/c/textimage.png");
print "Картинка создана";
?>

Re: Encoding problems

Posted: 2008-08-12T05:46:34-07:00
by AppleAp
Bonzo wrote:Try -annotate instead of draw.

Code: Select all

<?PHP
error_reporting(E_ALL);
system ("/usr/local/bin/convert /home/ayva/c/a.png -font /home/ayva/c/visitor1.ttf -gravity \"Center\" -annotate +0+0 'А Вот И Полли' /home/ayva/c/textimage.png");
print "Картинка создана";
?>
Thanks for quick reply Bonzo.

I'm sorry, but I have another problem running this code from PHP (also running my original code). I think it's because of quotes. When I run both codes from PHP, I get result, but without text.

Can you help me with this please? I can't use SSH for tests, because it looks like SSH clients don't support any non latin encodings (I can't even enter russian letters there).

Re: Encoding problems

Posted: 2008-08-12T08:01:31-07:00
by Bonzo
On windows you need to use " around code not ' Linux should be OK but it would be worth trying.

Also you do not need the quotes around Center; is this any different ? Also some other error reporting added.

Code: Select all

<?PHP
error_reporting(E_ALL);
$array=array();
echo "<pre>";
system ("/usr/local/bin/convert /home/ayva/c/a.png -font /home/ayva/c/visitor1.ttf -gravity Center -annotate +0+0 \" А Вот И Полли \" /home/ayva/c/textimage.png 2>&1", $array); 
print_r($array); 
echo "</pre>";
print "Картинка создана";
?>

Re: Encoding problems

Posted: 2008-08-12T09:28:23-07:00
by AppleAp
Bonzo wrote:On windows you need to use " around code not ' Linux should be OK but it would be worth trying.

Also you do not need the quotes around Center; is this any different ? Also some other error reporting added.

Code: Select all

<?PHP
error_reporting(E_ALL);
$array=array();
echo "<pre>";
system ("/usr/local/bin/convert /home/ayva/c/a.png -font /home/ayva/c/visitor1.ttf -gravity Center -annotate +0+0 \" А Вот И Полли \" /home/ayva/c/textimage.png 2>&1", $array); 
print_r($array); 
echo "</pre>";
print "Картинка создана";
?>
Bonzo, the output is:

0
Картинка создана

The image is still without text (looks like input file).

Re: Encoding problems

Posted: 2008-08-12T09:58:53-07:00
by Bonzo
I would go back to basics - put the font, photo and code in one folder and try it.

You are also missing a font size and colour but it should still use a default colour and size. Unless there are no defaults ?

This works for me on my localhost and windows XP machine:

Code: Select all

<?PHP
error_reporting(E_ALL);
$array=array();
echo "<pre>";
system ("convert flowers.jpg -fill black -font verdana.ttf -pointsize 50 -gravity Center -annotate +0+0 \" А Вот И Полли  \" textimage.png 2>&1", $array); 
print_r($array); 
echo "</pre>";
print "Картинка создана";
?>
I use Notepad++ and selected Encode in UTF-8 under format. If the encoding is wrong you usualy get some text but it would not be the text you expected.

Re: Encoding problems

Posted: 2008-08-12T11:15:44-07:00
by AppleAp
Bonzo wrote:I would go back to basics
Good idea.

Works when I upload Verdana font.

So, this is problem between ImageMagick and my font. Windows Vista shows "O" as icon for Verdana and "TT" for my font. What does that mean?

I wonder is there any tool to convert my font to ImageMagick compatible (change encoding or format or something else)?

Re: Encoding problems

Posted: 2008-08-12T11:34:54-07:00
by Bonzo
Your font is a ttf one so should work - I tried it and get a load of question marks !

I would look for another font as it may be easer than getting this one to work.

Re: Encoding problems

Posted: 2008-08-12T11:54:40-07:00
by AppleAp
Bonzo wrote:Your font is a ttf one so should work - I tried it and get a load of question marks !

I would look for another font as it may be easer than getting this one to work.
The thing is this is standard font for userbars, so I can't use another one. And it works well in Photoshop in Windows.

If it's not format problem, then maybe it's encoding problem. How can I convert it to normal TTF font?