This project has moved and is read-only. For the latest updates, please go here.

Arabic Annotation in an Image - Disconnected Letters

May 18, 2015 at 7:42 PM
I am trying to annotate an image with Arabic text, but unfortunately, the letters are shown disconnected. I tried changing the text encoding, but the result does not change. Also, the text direction did not work with me when I tried setting it to "TextDirection.RightToLeft". The text still shows from left to right which is not correct in Arabic language.

However, when I use the Graphics class and DrawString method (in native ASP.NET), I get Arabic text correctly with no issues in encoding. But the issue with this approach is that I lose the image resolution and sometimes I get an image double the size of its original.

I would really appreciate if you could help me in resolving this encoding issue in Magick.NET.

I am using the code shown below.


using (MagickImageCollection images = new MagickImageCollection())
MagickImage logo = new MagickImage("logo:");

MagickImage label = new MagickImage();
label.BackgroundColor = Color.Black;
label.FillColor= Color.White;
label.TextDirection = TextDirection.RightToLeft;
label.TextGravity = Gravity.East;
label.TextEncoding = Encoding.Unicode;
label.Read("label:" + "مرحبا بكم");
label.Extent(logo.Width, label.Height, Gravity.East);

using (MagickImage output = images.AppendVertically())
May 18, 2015 at 9:23 PM
It looks like the normal font render engine does not support this. You could use Pango for this:
MagickImage label = new MagickImage();
label.BackgroundColor = System.Drawing.Color.Black;
label.FontPointsize = 50;
label.Font = "Arial";
label.Read("pango:<span foreground=\"white\">" + "مرحبا بكم" + "</span>");
It seems the fill color is ignored and you will have to use the 'span trick'. I will try to figure out why the font color is not working when I have some spare time.
May 22, 2015 at 9:02 AM
Thanks a lot for the answer. It worked perfectly with me. Fill color also worked with me.