drawing a line on an image with PIL

Question:

I want to draw a line and show it.
assume I have a PIL image.

draw = ImageDraw.Draw(pilImage)
draw.line((100,200, 150,300), fill=128)

How can I show the image? Before drawing the line I could do:

imshow(pilImage)

but imshow(draw) does not show the image.

How do I convert this back to a PIL image?

Asked By: eran

||

Answers:

This should work:

from PIL import Image, ImageDraw
im = Image.new('RGBA', (400, 400), (0, 255, 0, 255)) 
draw = ImageDraw.Draw(im) 
draw.line((100,200, 150,300), fill=128)
im.show()

Basically using ImageDraw draw over the image, then display that image after changes, to draw a thick line pass width

draw.line((100,200, 150, 300), fill=128, width=3)
Answered By: Anurag Uniyal
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.