Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2021 13:51
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Write rtl (Persian, Arabic, Hebrew) text on images using python and pillow
# First of all you need install *libraqm* on your machin.
# 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.
import os
from PIL import Image, ImageDraw, ImageFont
def main():
image =, "nature.jpeg"))
font = ImageFont.truetype(
os.path.dirname(__file__), "vazir-font-v28.0.0", "Vazir-Regular.ttf"
text = "طبیعت زیبای دوست داشتنی"
canvas = ImageDraw.Draw(image)
canvas.text((0, 0), text, (255, 255, 255), font=font, direction="rtl"), "result.jpg"))
if __name__ == '__main__':
Copy link

arastu commented May 4, 2021


Copy link

arastu commented May 4, 2021


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment