简体   繁体   中英

PIL reducing image size just by opening and saving

I have these lines of code which open an image nature.jpg using PIL and again save it by the name new_nature.jpg

from PIL import Image
im              = Image.open("nature.jpg")
im.save("new_nature.jpg")

When I checked the sizes of the files, they were like this:
nature.jpg -> 1.3 MB (13,28,902 bytes)
new_nature.jpg -> 636.4 kB (6,36,354 bytes)
Their image type and resolution both were same.
This is the link for the image: http://www.youandthemat.com/wp-content/uploads/nature-2-26-17.jpg
Can anyone tell me why is this happening ?

JPEG images can be compressed and saved in different qualities. The quality can be any number between 1 (worst) and 95 (best). the default saving quality is 75, and to get a better quality image you should try something like this:

from PIL import Image
im = Image.open("nature.jpg")
im.save("new_nature.jpg", quality=95)

Read docomentishion here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM