Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5713 > unrolled thread

Usage of named entities (HTML) in imagettftext

Started byErwin Moller <erwinmollerusenet@xs4all.nl>
First post2012-04-25 11:18 +0200
Last post2012-04-26 09:50 +0200
Articles 10 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  Usage of named entities (HTML) in imagettftext Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-04-25 11:18 +0200
    Re: Usage of named entities (HTML) in imagettftext Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-25 08:06 -0400
      Re: Usage of named entities (HTML) in imagettftext Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-04-25 15:34 +0200
        Re: Usage of named entities (HTML) in imagettftext Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-25 09:41 -0400
        Re: Usage of named entities (HTML) in imagettftext Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-25 13:11 -0400
    Re: Usage of named entities (HTML) in imagettftext "Peter H. Coffin" <hellsop@ninehells.com> - 2012-04-25 07:21 -0500
      Re: Usage of named entities (HTML) in imagettftext Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-04-25 14:57 +0200
    Re: Usage of named entities (HTML) in imagettftext "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-25 19:17 +0200
    Re: Usage of named entities (HTML) in imagettftext "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-25 22:49 +0200
      Re: Usage of named entities (HTML) in imagettftext "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-04-26 09:50 +0200

#5713 — Usage of named entities (HTML) in imagettftext

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-04-25 11:18 +0200
SubjectUsage of named entities (HTML) in imagettftext
Message-ID<4f97c160$0$6919$e4fe514c@news2.news.xs4all.nl>
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 &copy;) 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 = " &empty;  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 &copy;, 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: 
&#8364;) to access characters in a font beyond position 127. The 
hexadecimal format (like &#xA9;) is supported. Strings in UTF-8 encoding 
can be passed directly.

     Named entities, such as &copy;, 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

[toc] | [next] | [standalone]


#5721

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-04-25 08:06 -0400
Message-ID<jn8pc5$99n$1@dont-email.me>
In reply to#5713
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 &copy;) 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 = " &empty; 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 &copy;, 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: &#8364;)
> to access characters in a font beyond position 127. The hexadecimal
> format (like &#xA9;) is supported. Strings in UTF-8 encoding can be
> passed directly.
>
> Named entities, such as &copy;, 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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5727

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-04-25 15:34 +0200
Message-ID<4f97fd51$0$6907$e4fe514c@news2.news.xs4all.nl>
In reply to#5721
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

[toc] | [prev] | [next] | [standalone]


#5728

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-04-25 09:41 -0400
Message-ID<jn8uue$8t2$1@dont-email.me>
In reply to#5727
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5730

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-04-25 13:11 -0400
Message-ID<jn9b7l$ocm$1@dont-email.me>
In reply to#5727
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5722

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2012-04-25 07:21 -0500
Message-ID<slrnjpfr1d.4ci.hellsop@nibelheim.ninehells.com>
In reply to#5713
On Wed, 25 Apr 2012 11:18:23 +0200, Erwin Moller wrote:
> It clearly states "Named entities, such as &copy;, 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

[toc] | [prev] | [next] | [standalone]


#5725

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-04-25 14:57 +0200
Message-ID<4f97f4cf$0$6870$e4fe514c@news2.news.xs4all.nl>
In reply to#5722
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&copy;, 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 &#x2205; 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

[toc] | [prev] | [next] | [standalone]


#5731

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-04-25 19:17 +0200
Message-ID<9vqptbFvvlU1@mid.uni-berlin.de>
In reply to#5713
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 &copy;) 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 = " &empty;  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 &copy;, 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: &#8364;) to access
> characters in a font beyond position 127. The hexadecimal format (like &#xA9;) is
> supported. Strings in UTF-8 encoding can be passed directly.
> 
>     Named entities, such as &copy;, 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.
&#123;)

(can have utf-8 sequences like &#123;)

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

/Str.

[toc] | [prev] | [next] | [standalone]


#5732

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-04-25 22:49 +0200
Message-ID<9vr6beF1ivU1@mid.uni-berlin.de>
In reply to#5713
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 &copy;, 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.

[toc] | [prev] | [next] | [standalone]


#5736

From"Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Date2012-04-26 09:50 +0200
Message-ID<jnauns$o46$1@dont-email.me>
In reply to#5732
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
--

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web