emcconville / wand

The ctypes-based simple ImageMagick binding for Python

Home Page:http://docs.wand-py.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

text_direction doesn't work.

GibreelAbdullah opened this issue · comments

I am trying to add a simple arabic text on a png file. I set the draw.text_direction = 'right_to_left' but the result is the same (text prints in left to right direction).

My code.

    with Image(filename="sample.png") as img:
        width, height = img.size
        with Drawing() as draw:
            draw.font = 'NotoNaskhArabic-Regular.ttf'
            draw.font_size = 40
            draw.text_direction = 'right_to_left' #This doesn't change anything
            draw.text(int(img.width / 2), int(img.height / 2),
                      'م كَانَ إِذَا دَخَلَ الْخَ')
            draw(img)

        cimg = img.clone()
        cimg.save(filename="result.png")

The result is shown below.

image

Expected - 'م كَانَ إِذَا دَخَلَ الْخَ'

This is not a wand issue. Use the pango coder for rendering right-to-left fonts.

from wand.image import Image
from wand.font import Font

# Note the `u` prefix before the string, and the `pango:` prefix before the actual text.
pango_markup = u'pango:م كَانَ إِذَا دَخَلَ الْخَ'

with Image(filename='wizard:') as img:
    w, h = img.size
    with Image() as pango:
        pango.font = Font(
            '/usr/share/fonts/google-noto-vf/NotoSansArabic-VF.ttf',
            40,
        )
        pango.read(filename=pango_markup)
        nw, nh = pango.size
        l = (w - nw) // 2
        img.composite(image=pango, left=l, top=0, operator='multiply')
    img.save(filename='output.png')

output

Thank you. I couldn't find this in the documentation.

I have another issue though. The Font doesn't change, i have tried with a lot of fonts by giving absolute path/ relative path but the output remains the same.

I have another issue though. The Font doesn't change, i have tried with a lot of fonts by giving absolute path/ relative path but the output remains the same.

Feel free to open a discussion for future questions seeking help. However, most font issues are between ImageMagick, fontconfig, and the OS. It's best to debug solutions via ImageMagick's CLI (following usage guide) before porting to Python.