Consider the example in earlier section where we cropped a region of an image. The cropped region contained a smiley face. Let's modify the original image so that it has a 'reflection' of the smiley face.
If not already, download the file
Crop.png
from the Packt website.Write this code by replacing the file path with appropriate file path on your system.
1 import Image 2 img = Image.open("C:\\images\\Crop.png") 3 # Define the elements of a 4-tuple that represents 4 # a bounding box ( region to be cropped) 5 left = 0 6 upper = 25 7 right = 180 8 lower = 210 9 bbox = (left, upper, right, lower) 10 # Crop the smiley face from the image 11 smiley = img.crop(bbox_1) 12 # Flip the image horizontally 13 smiley = smiley.transpose(Image.FLIP_TOP_BOTTOM) 14 # Define the box as a 2-tuple. 15 bbox_2 = (0, 210) 16 # Finally paste the 'smiley' on to the image. 17 img.paste(smiley, bbox_2) 18 img.save("C:\\images\\Pasted.png") 19 img.show()
First we open...