Replit changes RGB pixel values

Bug description:
When you change a pixel in an image and save it as a file in replit, it can change that pixel so it isn’t the same when you read the pixel again.

Expected vs Current Behavior:
It should return the same pixel

Steps to reproduce:
Open an image
Change the first pixel to (2,1,0)
Save the image
Open the image again
The first pixel is not equal to the (2.1,0)

Bug appears at this link: https://replit.com/@sparik7633/Replit-changes-pixel-values

Screenshot(s)/Screen Recording:

Browser/OS/Device: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0

Replit Profile: https://replit.com/@sparik7633

Might be an issue with the Python library or your code, have you tried the code on your on machine?

Alright, the issue is that you don’t change the filename variable.

import Image # PIL.Image
filename = "dillon.png" #filename of an image
try:
  img = Image.open(filename)#Opening the file
except:
  raise IndexError("File does not exist")#If the filename isn't found, return an error
img_size = img.size# Get the image file size
arr = list(img.getdata()) # Get the rgba pixels of the image
arr[0] = (2,1,0,255)#Setting the first pixel in the image to a random color
print(arr[0])
im2 = Image.new(mode="RGBA", size=img_size)
im2.putdata(arr)
im2.save("new.png")#Making new image called "new.png"
#you never rename the filename, still dillon.png
#so add:
filename = "new.png"
img = Image.open(filename)#Opening new.png
arr = list(img.getdata())#Getting list of pixels
print(arr[0])#printing first pixel
1 Like

Thank you so much. This was actually for another program, but I realized I messed up 3 lines in that program and it was not replit.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.