3

We have an Image processing microservice that created rich images with text on top of it and we are in the process of adding arabic locale to our website While translating some of the content to Arabic our translator told us that the text in generated images not rendering correctly in arabic - they appear with no ligatures, so every character is separated.

We currently use ImageMagick (6.8.9-9) with PHP and the text generation used ImagickDraw->annotateImage that worked fine until we hit that ligatures problem.

I googled a little and found "pango" that solves that problem and also allows some sort of "html" syntax to define multiple settings for one text line which is pretty cool. Problem is that I didn't find a way to use custom font files

This is the code:

$img = new \Imagick;
$img->newImage($width, $height, new ImagickPixel('transparent'));
$img->setBackgroundColor(new ImagickPixel('transparent'));
$img->setFont($fontFile); // didn't work
$img->setPointSize($fontSize);
$img->setOption("font", $fontFile); // didn't work
$img->newPseudoImage($width, $height, "pango:<span font='".$fontName."' foreground='".$textColor."'>".$text."</span>"); // font='".$fontName."' - also didn't work

I also tried to install the font in ubuntu OS and use only the font name but that didn't worked either, as well as combining all the options above or some of them.

I found that question: PHP Imagick don't use custom font > convert does. But he said he used "caption" instead of pango - which doesn't provide that cool "html" syntax and does not solve the Arabic issue.

Please - if you know any solution I will love you forever!

Thanks.

sUP
  • 614
  • 3
  • 16
  • 1
    In ImageMagick, you can add your own fonts to the type.xml file or use a script to catalog all your fonts to use names. Otherwise, you have to use paths to the font file. With regard to the arabic fonts, if they are UTF8 compatible you can write you text into a file using a UTF8 compatible editor. Then reference your text via the @textfile.txt syntax. See http://www.imagemagick.org/Usage/scripts/imagick_type_gen and http://www.imagemagick.org/Usage/text/#unicode. Also http://www.imagemagick.org/Usage/text/#label_lines for the @ syntaxI am not sure about the latter use in Pango nor in Imagick. – fmw42 May 08 '18 at 22:22
  • do you have found any solution for this ? – Arash Oct 30 '19 at 19:22
  • 1
    We actually moved to generate in the browser using canvas . It reduced the costs by a lot and it works – sUP Nov 27 '19 at 13:09

0 Answers0