October 13, 2022 at 7:01 PM
first u need pillow PIL library for python
u can change any pixel in an image
u can change any pixel in an image
from PIL import Image
old_image_name = input("Enter the name of the image that you want to change: ")
new_image_name = input("Enter the output file name (Default = output.format: ") or "output.{old_image_name.rsplit('.', 1)[-1]}"
image = Image.open(old_image_name) ## Insert any picture name here ##
pixel = image.load() # load pic so it can be scanned
size = image.size # Get the width and hight of the image for iterating over
##find the individual X and Y sizes so they can be iterated over
size_x = int(size[0])
size_y = int(size[1])
colour_counter = 0
for x in range (0, size_x): #loops through all the columns
for y in range (0, size_y): #loops through all the rows
current_pixel_value = pixel[x, y] # Get the RGBA Value of the pixel
colour_counter += 1
if colour_counter % 3 == 0:
pixel[x,y] = (0, 255, 0) # make pixel green
elif colour_counter % 2 == 0:
pixel[x,y] = (0, 0, 255) # make pixel blue
else:
pixel[x,y] = (255, 0, 0) # make pixel red
image.save(new_image_name) # Save the modified pixels as .png
