Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL image reproduction

I am new to PIL and Python and I have a question related to the API.

I have an Image

img = Image.new('RGB', (1, 2))

And I have a list of tuples

x = [(255, 255, 255), (255, 255, 255)]

I do img.putdata(x)

and img.save('C:\\somename.jpeg')

Later on when I reload the Image and do

img2 = Image.open('C:\\somename.jpeg')

y = [p for p in img2.getdata()]

The data 'y' that I actually get back is

[(255, 255, 255), (251, 251, 251)]

I am not able to understand why this is happening? Please let me know if anyone has some pointers related to this.

like image 709
AAK Avatar asked Dec 07 '25 06:12

AAK


1 Answers

jpeg is a lossy compression format and doesn't guarantee pixel by pixel reproduction. Try saving the image in a lossless format.

like image 168
tom10 Avatar answered Dec 09 '25 20:12

tom10



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!