@@ -47,6 +47,21 @@ helps with the reshaping so we can get the proper result like this:
4747```
4848import arabic_reshaper
4949
50+ text_to_be_reshaped = 'اللغة العربية رائعة'
51+ reshaped_text = arabic_reshaper.reshape(text_to_be_reshaped)
52+ ```
53+
54+ ### Example using PIL Image
55+
56+ PIL Image does not support reshaping out of the box, so to draw Arabic text on an ` Image ` instance you would need to reshape
57+ the text for sure.
58+
59+ For this example to work you need to run ` pip install --upgrade arabic-reshaper python-bidi pillow `
60+
61+ ```
62+
63+ import arabic_reshaper
64+
5065text_to_be_reshaped = 'اللغة العربية رائعة'
5166reshaped_text = arabic_reshaper.reshape(text_to_be_reshaped)
5267
@@ -65,11 +80,20 @@ bidi_text = get_display(reshaped_text)
6580# any other string. For example if you're using PIL.ImageDraw.text to draw
6681# text over an image you'd just use it like this...
6782
68- image = Image.new('RGBA', base.size, (255,255,255,0))
83+ from PIL import Image, ImageDraw, ImageFont
84+
85+ # We load Arial since it's a well known font that supports Arabic Unicode
86+ font = ImageFont.truetype('Arial', 40)
87+
88+ image = Image.new('RGBA', (800, 600), (255,255,255,0))
6989image_draw = ImageDraw.Draw(image)
70- image_draw.text((10,10), bidi_text, fill=(255,255,255,128))
90+ image_draw.text((10,10), bidi_text, fill=(255,255,255,128), font=font)
91+
92+ # Now the text is rendered properly on the image, you can save it to a file or just call `show` to see it working
93+ image.show()
7194
72- # See http://pillow.readthedocs.io/en/3.1.x/reference/ImageDraw.html?#PIL.ImageDraw.PIL.ImageDraw.Draw.text
95+ # For more details on PIL.Image and PIL.ImageDraw check the documentation
96+ # See http://pillow.readthedocs.io/en/5.1.x/reference/ImageDraw.html?#PIL.ImageDraw.PIL.ImageDraw.Draw.text
7397
7498```
7599
0 commit comments