snibgo's ImageMagick pages

Pango

ImageMagick can rasterise a simplified version of HTML.

Procedures described here were tested under Windows 8.1. The principles may be correct for other versions of Windows.

References:

See also my page UTF-8 characters.

Direct text from a command

Tell Windows to use a UTF code page by typing the following command:

chcp 65001
%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:"šŋĩβģő élève äëïöü" ^
  pa_pa.png
pa_pa.png
%IM%convert ^
  -size 400x200 -gravity SouthWest ^
  -background khaki ^
  -pointsize 30 ^
  pango:"šŋĩβģő élève äëïöü" ^
  pa_sw.png
pa_sw.png
%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:"šŋĩβģő élève äëïöü <u>underlined</u> <i>italic</i>" ^
  pa_marked.png
pa_marked.png
%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:"<i>A</i> &#x229B; <i>B</i> &#x21D2; <i>C</i>" ^
  pa_chars.png
pa_chars.png
%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  -font Courier-New ^
  pango:"<i>A</i> &#x229B; <i>B</i> &#x21D2; <i>C</i>" ^
  pa_chars2.png
pa_chars2.png

Indirect text from a file

%IM%convert ^
  -gravity Center ^
  -background khaki ^
  pango:@pango_test.txt ^
  pa_marked3.png
pa_marked3.png

The terminal cr-lf in the file influences the graphical output.

%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:@snibu8.txt ^
  pa_pa_t.png
pa_pa_t.png

The default font and size for pango is different from the other methods. In addition, "gravity center" doesn't centralise vertically.

Arabic

Arabic is written from right to left. Joined-up writing uses different glyphs from separated writing, even when printed or on computer screens.

According to Cambridge Dictionaries Online, the Arabic for "image" is "صَوْرة", and for "magic" is "سِحْر". So we have "صَوْرة سِحْر". Re-writing that phrase, with characters spaced so each is standalone, like "i m a g e m a g i c", looks like this: "صَ وْ ر ة سِ حْ ر".

With default rendering, each character is written separately, and in the wrong order (left to right):

%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:"صَوْرة سِحْر" ^
  pa_pa_a.png

Pango's default font doesn't include Arabic glyphs.
A font should be specified.

pa_pa_a.png

The IM setting "-direction" should be useful. In a right-to-left world, gravity is confused, and the automatic pointsize for caption and label doesn't work.

This needs a font to be specified.

%IM%convert ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -font Arial -pointsize 30 ^
  pango:"صَوْرة سِحْر" ^
  pa_pa_a2.png

The direction and glyphs are correct.

pa_pa_a2.png

Testing wordwrap.

%IM%convert ^
  -size 200x200 -gravity Center ^
  -background khaki ^
  -font Arial -pointsize 50 ^
  pango:"صَوْرة سِحْر" ^
  pa_pa_a2ww.png

This seems correct.

pa_pa_a2ww.png

Conclusion: for Arabic text, "pango:" is the obvious choice.

Some more examples of Pango, in English and Arabic:

Wordwrap.

%IM%convert ^
  -size 350x200 -gravity NorthEast ^
  -background khaki ^
  -font Arial -pointsize 30 ^
  pango:"wonderful powerful no-cost image magic" ^
  pa_pa_ex1.png
pa_pa_ex1.png

Wordwrap, with a forced new line.

%IM%convert ^
  -size 350x200 -gravity NorthEast ^
  -background khaki ^
  -font Arial -pointsize 30 ^
  pango:"wonderful powerful no-cost\nimage magic" ^
  pa_pa_ex2.png
pa_pa_ex2.png

Wordwrap.

%IM%convert ^
  -size 350x200 -gravity NorthWest ^
  -background khaki ^
  -font Arial -pointsize 30 ^
  pango:"رائع قَوي مَجّاني صَوْرة سِحْر" ^
  pa_pa_ex3.png
pa_pa_ex3.png

Wordwrap, with a forced new line.

%IM%convert ^
  -size 350x200 -gravity West ^
  -background khaki ^
  -font Arial -pointsize 30 ^
  pango:"رائع قَوي مَجّاني\nصَوْرة سِحْر" ^
  pa_pa_ex4.png
pa_pa_ex4.png

All images on this page were created by the commands shown, using:

%IM%identify -version
Version: ImageMagick 6.9.5-3 Q16 x86 2016-07-22 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Source file for this web page is pango.h1, which is encoded in UTF-8. To re-create this web page, execute "procH1 pango".


This page, including the images, is my copyright. Anyone is permitted to use or adapt any of the code, scripts or images for any purpose, including commercial use.

Anyone is permitted to re-publish this page, but only for non-commercial use.

Anyone is permitted to link to this page, including for commercial use.


Page version v1.0 3-Dec-2014.

Page created 24-Sep-2016 18:52:48.

Copyright © 2016 Alan Gibson.