Question

It seems that python has its own mind..

Here is how it looks in IDLE:

>>> a = Image.open("1.jpg")
>>> a.save("2.jpg")
>>> b = Image.open("1.jpg")
>>> c = Image.open("2.jpg")
>>> c == b
False
>>> c.getdata() == b.getdata()
False
>>> c.getdata()[0]
(243, 217, 130)
>>> b.getdata()[0]
(245, 215, 129)
>>> 

?!

I have tried it with different images, all came back like that..

thanks for helping :)

Was it helpful?

Solution

This has nothing to do with Python and everything to do with JPEG. JPEG is a lossy format and will generally not produce exactly the same data when you save a file. Depending on quality settings, it might not even be very close. This behavior is by design. To avoid this, don't use a lossy format. In particular, do not repeatedly load a JPEG, modify it, and save it as JPEG again. This produces generation loss, where the image gets a little worse each time you save it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top