Projjol
Projjol

Reputation: 1395

Image rotated by 0 degrees has a different base64 compared to the original image

I have an image that I have rotated by 0 degrees on PIL, the exact command being:

image = Image.open("filename.jpg")
rotated = image.rotate(0,expand=True)
rotated.save("filename2.jpg")

The base64 or even the sha1 hash of both these images is quite different. If the angle of rotation is 0, why should this be happening?

Upvotes: 2

Views: 488

Answers (1)

Eric Duminil
Eric Duminil

Reputation: 54293

Because jpg is lossy, just opening a jpg file and saving it again will result in loss of information and a different hash.

With png, you might get the exact same file as long as no other information (e.g. header with modification time) is updated. The pixels won't be modified after a 0° rotation, but the compression algorithm might yield a different binary file even if the image itself hasn't been touched.

To debug this behaviour, you could try it with a bmp file, save it again without rotation, save it again with rotation and check the hashes.

Upvotes: 3

Related Questions