Suresh
Suresh

Reputation: 88

Overriding Original image using pillow in python

I'm trying to edit an image using pillow. I see we have only options to save the edited image in new file.

Is there a way to override the original image while saving the edited image in pillow? just to know.

Upvotes: 5

Views: 15934

Answers (1)

Vadym
Vadym

Reputation: 1555

You can specify any path for a new file. If you want to replace original file - just use original file path as a new path:

from PIL import Image

size = (128, 128)
original_file_path = 'folder/file.jpg'

try:
    im = Image.open(original_file_path)
    im.thumbnail(size)
    im.save(original_file_path)
except IOError:
    print("cannot create thumbnail for", original_file_path)

Upvotes: 7

Related Questions