In this assignment, you create some functions that modify any image in a certain way.
In each case, you are creating an algorithm, or series of steps, that can be performed on any image that the function receives.
1) Create a function that resizes any image to 100 x 100 pixels and rotates it 90 degrees.
import PIL #You find your own image files img1 = PIL.Image.open('yourfile1.jpg') img2 = PIL.Image.open('yourfile2.jpg') def changer(img): #your code goes here modified1 = changer(img1) modified2 = changer(img2) #view the modified images however you like; #use show() or save() or view them in the console
2) Create a function that reduces an image to half of its original height and one third of its original width. Use the size attribute of the image object to figure out the original height and width. Hint: size is a list of two numbers, so you can use size[0] and size[1] in your code.
3) Create a function that puts a rectangular border around the outside of an image. You need to use the load() function to edit pixels and the Python Image Draw module to modify the pixel values. You choose the border color.
4) Modify your border function so that you can input the number of pixels wide the border should be.
Starter Code:
import PIL #You find your own image files img1 = PIL.Image.open('yourfile1.jpg') img2 = PIL.Image.open('yourfile2.jpg') #notice that this has a "thickness" parameter! def addborder(img, thickness): #your code goes here #should produce a 5 pixel border borders1 = changer(img1, 5) #should produce an 18 pixel border borders2 = changer(img2, 18)