0

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 ?

trahul
  • 21
  • 4
  • 1
    Possible duplicate of [python PIL save image different size original](https://stackoverflow.com/questions/33642690/python-pil-save-image-different-size-original) – MFisherKDX Mar 27 '19 at 20:26
  • Since JPEG is lossy, it's quite likely that even if you got all the parameters identical, the re-compressed image will be different (both in size and in content). If the quality settings (in your code left to default value) differ from the original (as seems to be in this case), that size difference will be significant. – Dan Mašek Mar 27 '19 at 21:37

1 Answers1

1

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.

RealA10N
  • 120
  • 1
  • 5
  • 19