bug using a £ sign

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
eswoosh
Posts: 7
Joined: 2011-09-17T15:20:23-07:00
Authentication code: 8675308

bug using a £ sign

Post by eswoosh »

Hi

searched everywhere on this forum and the web, no one seems to of come accross this issue, looking for some help please.

I'm using this code:
exec("convert -fill black -pointsize 18 \\-size 600x caption:@".$invoice_ext_id.".invoice.txt ".$temp_file_name.$invoice_ext_id."-B.jpg");


The php variables are just strings.

This code pulls in a text based file with multiple lines to create an invoice text area, which is later then copied into my final invoice image, and then into pdf - probably an easier way but it works.

My problem:
When reading in a caption file that contains a '£' that is a british pound sign [aka £ in html], the image stops rendering text at the point of the pound sign (£).

Any ideas? I wondered if there was a way to escape the sign or something?

[In more detail]
I pull values from a database prior to this stage, and insert them into a text file, each invoice line goes into a line textfile line (plain text).
This file is then read in using the imagemagick code posted above. So i do have control over what goes into the file - just a little lost with no supporting docs really.

Cheers
Paul
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug using a £ sign

Post by fmw42 »

When I write this in a (unicode compatible) text editor

convert -fill black -size 100x -pointsize 18 caption:'£' tmp.png

and then copy and paste to my terminal, I see the unicode equivalent in the terminal

convert -fill black -size 100x -pointsize 18 caption:'\302\243' tmp.png

which produces an image as expected of the £.

My suspicion is that your database conversion to your PHP is not handling the unicode character properly.

What happens with other similar kinds of unicode characters (such as ¢ © ™ or accented characters)? Do you have the same problem?

However, I will defer to the PHP experts on this.

I am running IM 6.7.2.7 Q16 Mac OSX Tiger (and used the text editor BBEdit).
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: bug using a £ sign

Post by Bonzo »

Could be the character encoding of the page you are running the php code on; what happens if you echo the variable with the £ without running the Imagemagick code?
eswoosh
Posts: 7
Joined: 2011-09-17T15:20:23-07:00
Authentication code: 8675308

Re: bug using a £ sign

Post by eswoosh »

Spot on with those answers guys.

Thanks.

For future reference / archive:

I use notepad++ to develop PHP, here's what I did:
1) I used the built in 'Convert to UTF-8' function on all code related to generating images with ImageMagick.
2) I used a PHP command: utf8_encode($my_text_variable);

I think the PHP command (in step 2) is what actually did the fix - useful little command that!

Now working great!
Cheers for your speedy, polite solutions - pointed me right at the problem, owe you one.

Paul
Post Reply