FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Usage of named entities (HTML) in imagettftext
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Usage of named entities (HTML) in imagettftext [message #177877] Wed, 25 April 2012 09:18 Go to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
Hello,

I just found something strange in the documentation (or my understanding
of it).
During some modification I am making to an older project I found I was
using named entities (like ©) during true type font rendering.
And that shouldn't work, according to the documentation, but it does
work just fine.

The function imagettftext(...) will write a text on an image-resource
using a True Type font.

Here follows a code snippet:
$inImgText = " ∅ 50 mm)";
imagettftext($myImg, $size, 0, $x, $y, $black, $font,$inImgText);

(I left not related code out.)

The result is the text: ∅ 50 mm appearing on the image, as intended.
(In case the characters didn't survive it to your newsreader, that is
DIAMETER symbol, followed by 50 mm)

But according to the documentation it shouldn't.
It clearly states "Named entities, such as ©, are not supported.".
(Relevant part copied hereunder)

What am I missing here?
Or is the documentation wrong and ARE named entities supported?

(I am using PHP 5.2.0 on this system)

Thanks for your time.

Regards,
Erwin Moller


[source]
http://nl3.php.net/manual/en/function.imagettftext.php
======================================================================
TEXT
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.

Named entities, such as ©, are not supported. Consider using
html_entity_decode() to decode these named entities into UTF-8 strings
(html_entity_decode() supports this as of PHP 5.0.0).

If a character is used in the string which is not supported by the
font, a hollow rectangle will replace the character.
======================================================================


--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: Usage of named entities (HTML) in imagettftext [message #177885 is a reply to message #177877] Wed, 25 April 2012 12:06 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/25/2012 5:18 AM, Erwin Moller wrote:
> Hello,
>
> I just found something strange in the documentation (or my understanding
> of it).
> During some modification I am making to an older project I found I was
> using named entities (like ©) during true type font rendering.
> And that shouldn't work, according to the documentation, but it does
> work just fine.
>
> The function imagettftext(...) will write a text on an image-resource
> using a True Type font.
>
> Here follows a code snippet:
> $inImgText = " ∅ 50 mm)";
> imagettftext($myImg, $size, 0, $x, $y, $black, $font,$inImgText);
>
> (I left not related code out.)
>
> The result is the text: ∅ 50 mm appearing on the image, as intended.
> (In case the characters didn't survive it to your newsreader, that is
> DIAMETER symbol, followed by 50 mm)
>
> But according to the documentation it shouldn't.
> It clearly states "Named entities, such as ©, are not supported.".
> (Relevant part copied hereunder)
>
> What am I missing here?
> Or is the documentation wrong and ARE named entities supported?
>
> (I am using PHP 5.2.0 on this system)
>
> Thanks for your time.
>
> Regards,
> Erwin Moller
>
>
> [source]
> http://nl3.php.net/manual/en/function.imagettftext.php
> ======================================================================
> TEXT
> 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.
>
> Named entities, such as ©, are not supported. Consider using
> html_entity_decode() to decode these named entities into UTF-8 strings
> (html_entity_decode() supports this as of PHP 5.0.0).
>
> If a character is used in the string which is not supported by the font,
> a hollow rectangle will replace the character.
> ======================================================================
>
>

This has nothing to do with PHP.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Usage of named entities (HTML) in imagettftext [message #177886 is a reply to message #177877] Wed, 25 April 2012 12:21 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Wed, 25 Apr 2012 11:18:23 +0200, Erwin Moller wrote:
> It clearly states "Named entities, such as ©, are not supported.".
> (Relevant part copied hereunder)
>
> What am I missing here?
> Or is the documentation wrong and ARE named entities supported?

It's not impossible that the doco is behind, or that the entity decoding
is incomplete or possibly incorrect occasionally. "Not supported"
includes the concept of "broken". (:

--
90. I will not design my Main Control Room so that every workstation is
facing away from the door.
--Peter Anspach's list of things to do as an Evil Overlord
Re: Usage of named entities (HTML) in imagettftext [message #177889 is a reply to message #177886] Wed, 25 April 2012 12:57 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 4/25/2012 2:21 PM, Peter H. Coffin wrote:
> On Wed, 25 Apr 2012 11:18:23 +0200, Erwin Moller wrote:
>> It clearly states "Named entities, such as©, are not supported.".
>> (Relevant part copied hereunder)
>>
>> What am I missing here?
>> Or is the documentation wrong and ARE named entities supported?
>
> It's not impossible that the doco is behind, or that the entity decoding
> is incomplete or possibly incorrect occasionally. "Not supported"
> includes the concept of "broken". (:
>

That is probably it: "not supported" as in "works occasionally: use at
your own risk".
I interpreted "not supported" as "won't work at all", hence my confusion.
I changed the named entity to ∅ which is probably more reliable
supported by GD2/PHP.

Thanks Peter.

Regards,
Erwin Moller


--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: Usage of named entities (HTML) in imagettftext [message #177891 is a reply to message #177885] Wed, 25 April 2012 13:34 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 4/25/2012 2:06 PM, Jerry Stuckle wrote:

>
> This has nothing to do with PHP.
>

Why not, Jerry?

If I see something working (as in producing the right result on the
actual image) and the PHPdocs says it is not supported, I wonder what is
going on.

GD(2) libs are used to do the actual rendering on the image, but it
isn't clear for the programmer (me) if PHP performs any funky stuff
(like html_entity_decode) on the strings before passing them through to GD.

http://www.libgd.org/ is down for some time now. I hoped to find some
info there first since boutell.com itself isn't very clear.
This is the best I could find (on boutell):
http://www.boutell.com/gd/manual2.0.33.html#fonts

But possibly I am looking in all the wrong places. :-(

Where would you suggest I should inquire about this 'issue' if not in
c.l.php?

Regards,
Erwin Moller


--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: Usage of named entities (HTML) in imagettftext [message #177892 is a reply to message #177891] Wed, 25 April 2012 13:41 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/25/2012 9:34 AM, Erwin Moller wrote:
> On 4/25/2012 2:06 PM, Jerry Stuckle wrote:
>
>>
>> This has nothing to do with PHP.
>>
>
> Why not, Jerry?
>
> If I see something working (as in producing the right result on the
> actual image) and the PHPdocs says it is not supported, I wonder what is
> going on.
>
> GD(2) libs are used to do the actual rendering on the image, but it
> isn't clear for the programmer (me) if PHP performs any funky stuff
> (like html_entity_decode) on the strings before passing them through to GD.
>
> http://www.libgd.org/ is down for some time now. I hoped to find some
> info there first since boutell.com itself isn't very clear.
> This is the best I could find (on boutell):
> http://www.boutell.com/gd/manual2.0.33.html#fonts
>
> But possibly I am looking in all the wrong places. :-(
>
> Where would you suggest I should inquire about this 'issue' if not in
> c.l.php?
>
> Regards,
> Erwin Moller
>
>

No, this is part of the GD library. All PHP has is a wrapper to the
library. PHP has no control over what characters the GD library supports.

You'll get much better answers if you ask in the GD library support
(sorry, I have no idea where this is - I never looked). They know what
their library is and is not capable of.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Usage of named entities (HTML) in imagettftext [message #177894 is a reply to message #177891] Wed, 25 April 2012 17:11 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/25/2012 9:34 AM, Erwin Moller wrote:
> On 4/25/2012 2:06 PM, Jerry Stuckle wrote:
>
>>
>> This has nothing to do with PHP.
>>
>
> Why not, Jerry?
>
> If I see something working (as in producing the right result on the
> actual image) and the PHPdocs says it is not supported, I wonder what is
> going on.
>
> GD(2) libs are used to do the actual rendering on the image, but it
> isn't clear for the programmer (me) if PHP performs any funky stuff
> (like html_entity_decode) on the strings before passing them through to GD.
>
> http://www.libgd.org/ is down for some time now. I hoped to find some
> info there first since boutell.com itself isn't very clear.
> This is the best I could find (on boutell):
> http://www.boutell.com/gd/manual2.0.33.html#fonts
>
> But possibly I am looking in all the wrong places. :-(
>
> Where would you suggest I should inquire about this 'issue' if not in
> c.l.php?
>
> Regards,
> Erwin Moller
>
>

One thing I should add - asking the GD Library support people will get
you information directly related to the version of the library you're
using, and not some general info from another product's (PHP's)
documentation which was relevant at the time it was written but may or
may not be now.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Usage of named entities (HTML) in imagettftext [message #177895 is a reply to message #177877] Wed, 25 April 2012 17:17 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 25.04.2012 11:18, schrieb Erwin Moller:
> Hello,
>
> I just found something strange in the documentation (or my understanding of it).
> During some modification I am making to an older project I found I was using named
> entities (like ©) during true type font rendering.
> And that shouldn't work, according to the documentation, but it does work just fine.
>
> The function imagettftext(...) will write a text on an image-resource using a True
> Type font.
>
> Here follows a code snippet:
> $inImgText = " ∅ 50 mm)";
> imagettftext($myImg, $size, 0, $x, $y, $black, $font,$inImgText);
>
> (I left not related code out.)
>
> The result is the text: ∅ 50 mm appearing on the image, as intended.
> (In case the characters didn't survive it to your newsreader, that is DIAMETER
> symbol, followed by 50 mm)
>
> But according to the documentation it shouldn't.
> It clearly states "Named entities, such as ©, are not supported.".
> (Relevant part copied hereunder)
>
> What am I missing here?
> Or is the documentation wrong and ARE named entities supported?
>
> (I am using PHP 5.2.0 on this system)
>
> Thanks for your time.
>
> Regards,
> Erwin Moller
>
>
> [source]
> http://nl3.php.net/manual/en/function.imagettftext.php
> ======================================================================
> TEXT
> 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.
>
> Named entities, such as ©, are not supported. Consider using
> html_entity_decode() to decode these named entities into UTF-8 strings
> (html_entity_decode() supports this as of PHP 5.0.0).
>
> If a character is used in the string which is not supported by the font, a hollow
> rectangle will replace the character.
> ======================================================================

I can tell you that the german help does not talk about named entities, it just says

Text ist der auszugebende String, der auch UTF-8-Zeichenfolgen enthalten darf (z.B.
{)

(can have utf-8 sequences like {)

Wrong is also the french and the spanish help. :-)

/Str.
Re: Usage of named entities (HTML) in imagettftext [message #177896 is a reply to message #177877] Wed, 25 April 2012 20:49 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 25.04.2012 11:18, schrieb Erwin Moller:
> Hello,
--cut

>
> But according to the documentation it shouldn't.
> It clearly states "Named entities, such as ©, are not supported.".
> (Relevant part copied hereunder)
>
> What am I missing here?
> Or is the documentation wrong and ARE named entities supported?

To make the thread complete, here a minimal test program: (adjust the path to your
ttf font)

<?php
Header ("Content-type: image/gif");
$im = imagecreate (400, 30);
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
ImageTTFText ($im, 20, 0, 10, 20, $white,
"/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf",
"&laquo;Test&raquo; &copy; /Str. Omega: &#937;");
ImageGif ($im);
ImageDestroy ($im);


Have fun testing.

/Str.
Re: Usage of named entities (HTML) in imagettftext [message #177900 is a reply to message #177896] Thu, 26 April 2012 07:50 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 25/04/2012 22:49, M. Strobel escribió/wrote:
> To make the thread complete, here a minimal test program: (adjust the path to your
> ttf font)
>
> <?php
> Header ("Content-type: image/gif");
> $im = imagecreate (400, 30);
> $black = ImageColorAllocate ($im, 0, 0, 0);
> $white = ImageColorAllocate ($im, 255, 255, 255);
> ImageTTFText ($im, 20, 0, 10, 20, $white,
> "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf",
> "&laquo;Test&raquo;&copy; /Str. Omega:&#937;");
> ImageGif ($im);
> ImageDestroy ($im);

It works as advertised here (PHP/5.3.10 on Windows): only numeric
entities get parsed. Which is crazy enough: I don't even know by heart
what PHP function can be used to escape HTML entities (using numeric
notation) but not HTML tags.

I've had lots of similar problems working with text and image*
functions, such as non-ASCII characters completely breaking in one minor
update and getting fixed in the next one, or text align algorithm
getting replaced by a worse one without prior notice. I guess that's the
way life is.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: What happens when i dont use the semicolon for closing my statement
Next Topic: Data injection problems
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 08:31:20 GMT 2024

Total time taken to generate the page: 0.02069 seconds