Add Text on Image using PIL

后端 未结 8 1268
后悔当初
后悔当初 2020-12-07 08:02

I have an application that loads an Image and when the user clicks it, a text area appears for this Image (using jquery), where user can write some text on the

8条回答
  •  Happy的楠姐
    2020-12-07 08:23

    With Pillow, you can also draw on an image using the ImageDraw module. You can draw lines, points, ellipses, rectangles, arcs, bitmaps, chords, pieslices, polygons, shapes and text.

    from PIL import Image, ImageDraw
    blank_image = Image.new('RGBA', (400, 300), 'white')
    img_draw = ImageDraw.Draw(blank_image)
    img_draw.rectangle((70, 50, 270, 200), outline='red', fill='blue')
    img_draw.text((70, 250), 'Hello World', fill='green')
    blank_image.save('drawn_image.jpg')
    

    we create an Image object with the new() method. This returns an Image object with no loaded image. We then add a rectangle and some text to the image before saving it.

提交回复
热议问题