Search code examples
pythonpython-3.xopencvpython-imaging-library

How can I draw a curved text using python? Converting text to curved image?


I want to write a python program that converts given text into an image. There are tutorials for it online, but I want to curve the text over a circle.

Let's say I have the text "YOUR CURVED TEXT".

I want to draw this on an image and end up with something like following:

Final result after processing the image

I checked Pillow and OpenCV. I might be making a mistake but I don't think they have any functionality for curving the given text?

What would be the best way to do this?

Thanks in advance.


Solution

  • You can do something like that in ImageMagick using -distort arc 360.

    convert -font Arial -pointsize 20 label:' Your Curved Text  Your Curved Text ' -virtual-pixel Background  -background white -distort Arc 360  -rotate -90  arc_circle_text.jpg
    

    enter image description here

    You can do that also in Python Wand, which uses ImageMagick as follows:

    from wand.image import Image
    from wand.font import Font
    from wand.display import display
    
    with Image() as img:
        img.background_color = 'white'
        img.font = Font('Arial', 20)
        img.read(filename='label: Your Curved Text  Your Curved Text ')
        img.virtual_pixel = 'white'
        # 360 degree arc, rotated -90 degrees
        img.distort('arc', (360,-90))
        img.save(filename='arc_text.png')
        img.format = 'png'
        display(img)
    

    enter image description here

    Thanks to Eric McConville for helping with the label: code.