trahul
trahul

Reputation: 21

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 ?

Upvotes: 0

Views: 477

Answers (1)

RealA10N
RealA10N

Reputation: 130

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.

Upvotes: 1

Related Questions