0

I've looked everywhere, but I can't figure out why I am facing this problem.

I am using phpThumb to do add some text (watermark) on some photos. The problem is that I need to use the special characters from Norway (æøå). These don't play so nice with ImageTTFtext.

enter image description here

The picture above contains the code for æ and should (according to the documentation) be correct. I've also tried some functions I found here on stack, but everything returns the same. Why does it print the code and not the actual character I am trying to display?

Is this due to old version of some software or something?

Versions:

PHP 5.3.2
ImageMagick 6.5.7
GD: 2.0

EDIT: Just to make it clear, I am passing the text the "correct" way according to the docs. Passing utf_encode('€') as the argument SHOULD WORK.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • What is the literal string you pass to that function? How do you call that function? It is *highly likely* you pass your string as exactly that to ImageTTFtext. Then it would be no wonder you see that, so not a real question. – hakre Oct 30 '12 at 17:26
  • Additionally, if you followed other answers it is required that you tell what exactly you've done so far and you tell exactly *why* existing answers did not help you in your question. – hakre Oct 30 '12 at 17:27
  • @hakre: Have I missed something essential? I just call it with for example `"€"` as an argument to the function. The docs says it should be a string. – OptimusCrime Oct 30 '12 at 20:01
  • did you tried to write your text after passing it to [html_entity_decode](http://fr2.php.net/manual/en/function.html-entity-decode.php) ? – Alain Tiemblo Oct 30 '12 at 20:46
  • @Ninsuo : Yes I did, but I solved the problem. Turned out the "built in" font did not support the special characters. As soon as I uploaded my own it worked like a charm. Thanks anyways – OptimusCrime Oct 30 '12 at 20:57
  • The function [`imagettftext`](http://php.net/imagettftext) you relate to in the question has no optional fontfile parameter. Add your code next time, so these obvious errors would be visible straight away. – hakre Oct 30 '12 at 21:03

2 Answers2

0

You are concerned about the text parameter of imagettftext. Let's review it's documentation:

The text string in UTF-8 encoding.

May include decimal numeric character references (of the form: € [€]) to access characters in a font beyond position 127. The hexadecimal format (like © [©]) is supported. Strings in UTF-8 encoding can be passed directly.

In your question you have neither posted the code you are using nor did you specifiy the literal string used. For example if you pass a string "î" you will see î. So the display itself you added to your question might demonstrate what you experience as an issue, but the display itself might be totally unrelated to it's cause. The cause would be the string then.

Next to that the function is part of the gd extension, not ImageMagick.

The PHP version 5.3.2 is also out of date, however I have not scanned the changelog of it (nor the GD library version you use) if there is an error that matches what you have described. But it seems possible.

In any case should imagettftext display the text correctly. Even if a character is not found, you would see something different.

If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character. From the parameters description:

Provide a hex-dump of the string you pass to that function and add it to your question.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • Thank you for your reply, but I just answered it myself. I did everything you wrote. I used the correct string (copypasted from the phpdocs) and I tried every combination of `html_entity`, `utf8_encode/decode` and so on. Turns out the standard font the library uses does not support my characters. – OptimusCrime Oct 30 '12 at 20:59
  • Well in no way did *I* suggest you should try combinations of diverse string function incl. *html_entity* or `utf8_encode` or whatever. I just asked for clarification and before jumping to conclusions I explicitly wrote that you need to provide more information like the code-snippet this is related to and a hexdump of the string. – hakre Oct 30 '12 at 21:05
0

Answering this so anyone facing the same problem as me can find a solution.

It turns out the "built in" font from GD did not support my special characters. Upload your own fonts and use them in the function, it should work.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • built in? The *fontfile* parameter does not look optional to me. Also you didn't post any code in the question, so it was completely hidden that you didn't specify any font. – hakre Oct 30 '12 at 21:02
  • Same problem here - so how do you use the fonts special characters? – v3nt Oct 30 '13 at 13:00
  • @danielCrabbe: See the documentation http://us2.php.net/imagettftext. In the argument, you just specify the location of the font-file (if it's not one of the built-in ones). If you are using a custom one you can download them (.ttf). Remember to point to the file relative to the script. – OptimusCrime Oct 30 '13 at 13:15
  • The font is already specified & working - just not those characters which i had to re-encode for the string using html_entity_decode($text); – v3nt Nov 07 '13 at 12:22