Closed ahmed4end closed 4 years ago
Please post your code, the font you're using, and the text you're reshaping, so I can help you further.
@mpcabd `from PIL import Image, ImageDraw, ImageFont from arabic_reshaper import ArabicReshaper from bidi.algorithm import get_display import os
size = (300,200) image = Image.new(mode = "RGBA" , size=size , color="white" ) draw = ImageDraw.Draw(image)
fnt = ImageFont.truetype(os.path.join(os.getcwd()+ "\TahaBold.ttf") , 100) text = "تجربة " configuration = { 'use_unshaped_instead_of_isolated': True, } reshaper = ArabicReshaper(configuration) reshaped_text = reshaper.reshape(text) bidi_text = get_display(reshaped_text)
text_size = draw.textsize(text, fnt) #
draw.text((size[0]-text_size[0],0), bidi_text, "black", font=fnt) draw.rectangle([size[0]-3, 0, size[0]-text_size[0], text_size[1]], fill=None, outline="black", width=3)
image.save(f"image.png");os.startfile("image.png")`
oh my bad, i calculated the text size for the raw text instead of the reshaped one and that made the problem for me, never mind.
for many fonts there are many words that when reshaping it appears to have wrong text size . when i try to get the text size for most of words i get it wrong as shown:
the bounding box shows the text size found by "[pillow object] draw.textsize(text, font)" there is extra space to the right that make it hard to use the reshaped result in any work !