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
%IMG7%magick ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:"šŋĩβģő élève äëïöü" ^
  pa_pa.png
pa_pa.png
%IMG7%magick ^
  -size 400x200 -gravity SouthWest ^
  -background khaki ^
  -pointsize 30 ^
  pango:"šŋĩβģő élève äëïöü" ^
  pa_sw.png
pa_sw.png
%IMG7%magick ^
  -size 400x200 -gravity Center ^
  -background khaki ^
  -pointsize 30 ^
  pango:"šŋĩβģő élève äëïöü <u>underlined</u> <i>italic</i>" ^
  pa_marked.png
pa_marked.png
%IMG7%magick ^
  -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
%IMG7%magick ^
  -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

%IMG7%magick ^
  -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.

%IMG7%magick ^
  -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):

%IMG7%magick ^
  -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.

%IMG7%magick ^
  -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.

%IMG7%magick ^
  -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.

%IMG7%magick ^
  -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

With an emoji (😀).

%IMG7%magick ^
  -size 350x200 -gravity NorthEast ^
  -background khaki ^
  -font Arial -pointsize 30 ^
  pango:"wonderful <span font=""Segoe UI Emoji"">&#x1F600;</span> image magic" ^
  pa_pa_ex1a.png
pa_pa_ex1a.png

Wordwrap, with a forced new line.

%IMG7%magick ^
  -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.

%IMG7%magick ^
  -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.

%IMG7%magick ^
  -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:

%IMG7%magick -version
Version: ImageMagick 7.1.0-42 Q16-HDRI x64 396d87c:20220709 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenCL 
Delegates (built-in): bzlib cairo freetype gslib heic jng jp2 jpeg jxl lcms lqr lzma openexr pangocairo png ps raqm raw rsvg tiff webp xml zip zlib
Compiler: Visual Studio 2022 (193231332)

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 13-Aug-2022 22:19:08.

Copyright © 2022 Alan Gibson.