pango: errors with (html) entities

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?".
ohnonot
Posts: 13
Joined: 2012-09-12T03:41:25-07:00
Authentication code: 67789

pango: errors with (html) entities

Post by ohnonot »

I'm using convert ... pango: to create an image from text, inside a linux bash script.
The creation fails when the text contains "weird characters" like & öäå etc.:

Code: Select all

Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 3: Entity name ' some &#246' is not known
convert: Error on line 3: Entity name ' some &#246' is not known `<span size="55555">\npiekoz - Turntable Man
(what i should&apos;ve done)  &amp; some &#246;&#228;</span>' @ error/pango.c/ReadPANGOImage/342.
In this example I added some extra characters to the dynamic test for testing: '& some öä', then used recode (linus utility) to convert it to html.

Even when I manually write out '&amp;', it fails:

Code: Select all

Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 2: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;
convert: Error on line 2: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp; `<span size="55555">\nbla &amp; bla</span>' @ error/pango.c/ReadPANGOImage/342.

What's going on? I feel like I'm missing something obvious here; surely pango's purpose is to make these kind of things easier?

Code: Select all

$> convert --version
Version: ImageMagick 6.9.8-3 Q16 x86_64 2017-03-25 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP 
Delegates (built-in): bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib

$> bash --version
GNU bash, version 4.4.12(1)-release (x86_64-unknown-linux-gnu)
Last edited by ohnonot on 2017-04-06T14:31:06-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pango: errors with (html) entities

Post by fmw42 »

What was your IM version and platform. Please always provide that. What was your exact command?

You cannot type entity codes in the text. You must type the text you want using a UTF-8 text editor and with a font that supports Unicode characters.
ohnonot
Posts: 13
Joined: 2012-09-12T03:41:25-07:00
Authentication code: 67789

Re: pango: errors with (html) entities

Post by ohnonot »

^ damn you're quick.
version added.
platform is archlinux.
fmw42 wrote: 2017-04-06T14:30:55-07:00What was your exact command?

Code: Select all

	pangostring="<span size=\"55555\">\n$(recode ..h0 <<<"$(mpi-panel -u -l2 -w100)")</span>"
	convert -background "$color1" -fill "$color2" -gravity center -size "$((${screensize%%x*} / 2))" pango:"$pangostring" -extent $screensize -quality 99 "$tmpfile"
this is the full convert command, as part of a shell script.
It works fine for normal song titles (that's what mpi-panel provides), but as soon as there's an & in the title, i get an empty canvas, with or without the 'recode' bit.
You cannot type entity codes in the text. You must type the text you want using a UTF-8 text editor and with a font that supports Unicode characters.
i'm not sure i understand?
the text is the output from another script, and i'm pretty sure it provides unicode characters.

but the convert command fails even if i don't convert the chars:

Code: Select all

pangostring="<span size=\"55555\">\nthis & that</span>"
error:

Code: Select all

Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 2: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;
convert: Error on line 2: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp; `<span size="55555">\nthis & that</span>' @ error/pango.c/ReadPANGOImage/342.
thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pango: errors with (html) entities

Post by fmw42 »

I tested the following and get the same error message:

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"&åß∂ƒ©" tmp.png
(process:224): Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;
convert: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp; `&åß∂ƒ©' @ error/pango.c/ReadPANGOImage/342.


and also

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"&amp;åß∂ƒ©" tmp.png
(process:397): Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;
convert: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp; `&amp;åß∂ƒ©' @ error/pango.c/ReadPANGOImage/342.



and also

Code: Select all

im6983pango convert -size 100x100 -font arial -gravity center pango:"\&åß∂ƒ©" tmp.png
(process:301): Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp;
convert: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity - escape ampersand as &amp; `\&åß∂ƒ©' @ error/pango.c/ReadPANGOImage/342.


Using IM 6.9.8.3 Q16 Mac OSX with pango @1.40.3_1+quartz+x11

I am not sure why it does not work. Perhaps it is a bug in IM or Pango

It does work fine if you use label: rather than pango:

Code: Select all

convert -size 100x100 -font arial -gravity center label:"&amp;åß∂ƒ©" tmp.png
or

Code: Select all

convert -size 100x100 -font arial -gravity center label:"&åß∂ƒ©" tmp.png
ohnonot
Posts: 13
Joined: 2012-09-12T03:41:25-07:00
Authentication code: 67789

Re: pango: errors with (html) entities

Post by ohnonot »

I was hoping to use pango because text spans over 4 lines with 3 different font sizes.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pango: errors with (html) entities

Post by fmw42 »

I understand. I have submitted a bug report on the Bugs forum. What is your pango version?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pango: errors with (html) entities

Post by fmw42 »

Here is a workaround. Escape the ; as \;

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"&amp\;åß∂ƒ©" tmp.png
It seems to work for me. Note pango does not seem to support -gravity, so my -gravity is ignored. I suppose you need to write it in pango markup.
ohnonot
Posts: 13
Joined: 2012-09-12T03:41:25-07:00
Authentication code: 67789

Re: pango: errors with (html) entities

Post by ohnonot »

thanks a bunch, that works:

Code: Select all

pangostring="<span size=\"55555\">\n$(recode ..h0 <<<"$(mpi-panel -u -l2 -w100)" | sed 's/;/\\;/g')</span>"
btw, i did some testing and at least one other pango-aware application does not display this behavior.
i wonder if i should file a bug with imagemagick...

fmw42 wrote:Note pango does not seem to support -gravity, so my -gravity is ignored. I suppose you need to write it in pango markup.
partly; it seems '-gravity center' is translated to 'align: center', so it applies only horizontally.

I did it like this:
1) make pango write to a canvas that is half the screen size
2) use -extent to resize the canvas to screensize (here '-gravity center' works again, so the text is centered.

it actually fits my requirements perfectly like that.

Code: Select all

convert -gravity center -size "$((${screensize%%x*} / 2))" pango:"$pangostring" -extent $screensize somefile.png
ohnonot
Posts: 13
Joined: 2012-09-12T03:41:25-07:00
Authentication code: 67789

Re: pango: errors with (html) entities

Post by ohnonot »

PS: what is that authentication code in my sidebar? it seems i can't remove it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pango: errors with (html) entities

Post by fmw42 »

ohnonot wrote: 2017-04-06T23:40:36-07:00 PS: what is that authentication code in my sidebar? it seems i can't remove it.
Sorry, I do not know to what you are referring.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pango: errors with (html) entities

Post by snibgo »

Other workarounds:

1. Prefix with backslash, eg

Code: Select all

convert -size 100x100 -font arial -gravity center pango:"hello \&amp; world" t.png
Yes, this works on Windows, where backslash isn't the escape.

2. Put the pango string in a file, at @ it, eg put

Code: Select all

Hello &amp; world
... into pangoamp.txt, then:

Code: Select all

convert -size 100x100 -font arial -gravity center pango:@pangoamp.txt t.png
snibgo's IM pages: im.snibgo.com
ohnonot
Posts: 13
Joined: 2012-09-12T03:41:25-07:00
Authentication code: 67789

Re: pango: errors with (html) entities

Post by ohnonot »

thanks to all!

what is that authentication code in the sidebar? i can see that snibgo also has it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pango: errors with (html) entities

Post by snibgo »

"Authentication code" is some PHP thingy. I think that users who are currently logged in have one, and users who aren't logged in don't.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pango: errors with (html) entities

Post by fmw42 »

I think the Authentication code is used on the sidebar if you have not filled in a Location in your member profile. If you look at the sidebar next to my post, it shows my Locations as Sunnyvale, CA rather than an Authentication code.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pango: errors with (html) entities

Post by snibgo »

Good theory, Fred, so I gave my location (and it required a new Authentication code). But now the sidebar shows both.
snibgo's IM pages: im.snibgo.com
Post Reply