Md Shopon
Md Shopon

Reputation: 823

Wrong plotting of unicode text in image using python

I was trying to plot unicode text(BANGLA) in a image using python IMAGE library. But it is not plotting the text correctly. In Bangla there are joint characters, the word "চট্টগ্রাম" contains a few joint characters if I extract the joint characters it would look something like this "চটটগরাম". But I am trying to plot the image as the original word but its plotting the extracted form of the word. Is there any solution of it? The code i used for this is

image = Image.new("RGBA", (width, height), text_color)
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font_path, fontsize, encoding="unicode")

w, h = font.getsize(txt_date)

# xy – Top left corner of the text.
draw.text(((width-w)/2, (height-h)/2), txt_date), background_color, font=font)
img_resized = image.resize((width, height), Image.ANTIALIAS)

enter image description here

Upvotes: 2

Views: 466

Answers (2)

Saiful Islam
Saiful Islam

Reputation: 11

I have save problem but at last i solve it,if you solve this problem follow this instruction,

sudo apt-get install libfreetype6-dev libharfbuzz-dev libfribidi-dev gtk-doc-tools

then clone pillow git and go depends folder

Run,

chmod +x install_raqm.sh
./install_raqm.sh

Uninstall your previous pillow version and install,

conda install pillow=6.0.0

Upvotes: 1

Lawrence D'Oliveiro
Lawrence D'Oliveiro

Reputation: 2804

Your image library probably has no clue about drawing anything other than the most basic forms of text. That means no support for mandatory contextual forms, as in Indic scripts.

To get such text looking right, you will need to render it into a separate image using a more sophisticated text layout library, and then composite that into the final image somehow (presumably the image library can cope with that).

HarfBuzz is a library that can do context-dependent text “shaping” according to rules specified in OpenType fonts. I did a Python 3 binding for it here.

Upvotes: 0

Related Questions