Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a PIL ImageDraw to Image

I have a PIL image:

img=Image.open(...)

that I convert to an ImageDraw to write in it.

img=ImageDraw.Draw(img)

Now I put the text in:

img.text((0,0), 'text', (0,0,0))

and now I want it BACK AS AN IMAGE

I was hoping for something like this:

img = Image.fromdraw(img)

I need my image in this format, for further processing.

How do I do that?

like image 450
Carol Eisen Avatar asked Oct 29 '25 14:10

Carol Eisen


1 Answers

ImageDraw draws on your original image, therefore you should keep both instances (Image and ImageDraw objects) in separate variables.

img = Image.open(...)
draw = ImageDraw.Draw(img)
draw.text((0,0), 'text', (0,0,0))
# img is modified inplace
like image 100
Whole Brain Avatar answered Oct 31 '25 06:10

Whole Brain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!