Reputation: 139
Why does the size of the jpg file reduce when we open and save an image using PIL in python?
img = Image.open("Koala.jpg") # Size of the image is 763 KB
width,height = img.size
pixel_values = list(img.getdata())
im= Image.new('RGB', (1024, 768))
im.putdata(pixel_values)
im.save('test.jpeg') # Size of the image is 142 KB
Upvotes: 2
Views: 134
Reputation: 29314
JPEG is a lossy format. The size changes because you are saving it with Pillow's encoder which is very likely different to the one the image was originally created with. Also using a different quality makes a difference.
Upvotes: 2