Python Imaging Library - Text rendering

前端 未结 6 936
终归单人心
终归单人心 2020-11-28 03:49

I\'m trying to render some text using PIL, but the result that comes out is, frankly, crap.

For example, here\'s some text I wrote in Photoshop:

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 04:08

    Suggestion: use Wand or a different Imaging library

    Here's an example with wand -

    from wand.color import Color
    from wand.image import Image
    from wand.drawing import Drawing
    from wand.compat import nested
    
    with Drawing() as draw:
        with Image(width=1000, height=100, background=Color('lightblue')) as img:
            draw.font_family = 'Indie Flower'
            draw.font_size = 40.0
            draw.push()
            draw.fill_color = Color('hsl(0%, 0%, 0%)')
            draw.text(0,int(img.height/2 + 20), 'Hello, world!')
            draw.pop()
            draw(img)
            img.save(filename='image.png')
    

提交回复
热议问题