Skip to content Skip to sidebar Skip to footer

Python Pil Save Image Different Size Original

I´m working on a project with PIL in python. Simply by opening and saving an image makes the output image bigger (in Bytes) than the original, maintaining the same resolution, and

Solution 1:

PNG is a compressed lossless format. The original image was probably saved with different compression settings.

Looking at the documentation you could try:

img.save("photo2.png", "PNG", optimize=True)

or

img.save("photo2.png", "PNG", compress_level=9)

By default, compress_level=6 is used.

Note that the optimize option includes setting the compression level to 9. But it also tries to find optimal encoder settings.

Solution 2:

I guess you don't change the image, otherwise the size would be different. If you don't change the image why don't you just copy it?

shutil.copyfile(source, destination)  

Post a Comment for "Python Pil Save Image Different Size Original"