Here's my code: Each function should have an img parameter plus any parameter specified in the comments to determine how the image will be filtered/edited. Each parameter needed is shown at the end of each function
rotating the image
from PIL import Image
img = Image.open("photot.jpeg")
w, h = (img.size)
def rotate():
for x in range(w):
for y in range(h):
px = img.getpixel((x, y))
target_x = (h - 1) - y
img.putpixel((target_x, x), px)
rotate()
img.save("rotate.jpeg")
<pre>
need to use the parameter "img" and "degrees" degrees will be 90, 180 or 270
inverting image
def invert_colors():
for x in range(w):
for y in range(h):
(r, g, b) = img.getpixel((x,y))
###print(r, g, b)
px = img.putpixel((x,y), (255 - r, 255 - g, 255 - b))
invert_colors()
img.save("invert.jpeg")
<pre>
needs the parameter "img"
def mirror():
for y in range(int(h/2)):
for x in range(w):
px = img.getpixel((x,y))
target_y = (h - 1) - y
img.putpixel((x, target_y), px)
mirror()
img.save("mirror_v.jpeg")
<pre>
needs the parameter "img","axis" and "start=0"
axis is horizontal or vertical
start value is 0 (zero) or "mid", which will determine whether the m
def remove_red():
for x in range(w): # loop the width
for y in range(h): # loop the height
r,g,b = img.getpixel((x,y))
# get the rgb values of the sourcepixel
# if b < g and b < r or r==g==b:
img.putpixel((x,y), (0,g,b)) # update the target image
remove_red()
img.save('remove_red.jpeg')
<pre>needs the parameter "img"
NOTE: you're using only the Image class of the Python Imaging LIbrary, and the only
methods you are to use are
.new()
.open()
.getpixel()
.putpixel()
.save()
What I have tried:
I've written most of the code I just dont know what and how to change the code to accept the parameters