You can use Pillow without arabic_reshaper.
First of all you need have libraqm on your path. The Raqm library encapsulates the logic for complex text layouts and provides a convenient API. libraqm relies on the following libraries: FreeType, HarfBuzz, FriBiDi, make sure that you install them before installing libraqm if not available as package in your system.
if you using macos you can install libraqm with homebrew
brew install libraqm
Pillow wheels since version 8.2.0 include a modified version of libraqm that loads libfribidi at runtime if it is installed.
The .text function takes the direction argument to the
libraqm library, which enables pillow to support bidirectional text (using FriBiDi), shaping (using HarfBuzz), and also proper script itemization.
Additionally, you need a font for the language you wish to write in, such
as an Arabic font.
import os
from PIL import Image, ImageDraw, ImageFont
def main():
image = Image.open(os.path.join(os.path.dirname(__file__), "nature.jpeg"))
font = ImageFont.truetype(
os.path.join(
os.path.dirname(__file__), "vazir-font-v28.0.0", "Vazir-Regular.ttf"
),
100,
)
text = "طبیعت زیبای دوست داشتنی"
canvas = ImageDraw.Draw(image)
canvas.text((0, 0), text, (255, 255, 255), font=font, direction="rtl")
image.save(os.path.join(os.path.dirname(__file__), "result.jpg"))
if __name__ == '__main__':
main()