In [3]:
from PIL import Image
myim = Image.open("roxy.jpg")
def crop_img():
box = (100, 100, 900, 500) #CROPPING-left, upper, right, lower
region = myim.crop(box)
region.save("croro"+".jpg")
print ("The size of the Image is: ")
print(region.size, region.mode)
region.show()
def squae_padding():
longer_side = max(myim.size) #square padding
horizontal_padding = (longer_side - myim.size[0]) / 2
vertical_padding = (longer_side - myim.size[1]) / 2
new = myim.crop(
(
-horizontal_padding,
-vertical_padding,
myim.size[0] + horizontal_padding,
myim.size[1] + vertical_padding
)
)
new.save("square.jpg")
new.show()
def gray():
greyscale_image = myim.convert('L')
greyscale_image.save('greyscale.jpg')
greyscale_image.show()
def centrecrop():
half_the_width = myim.size[0]/2
half_the_height = myim.size[1]/2
croppp = myim.crop(
(
half_the_width-50,
half_the_height-625,
half_the_width+600,
half_the_height+325
)
)
croppp.save("croppp.jpg")
croppp.show()
print("choose the activity:")
print("press 1 for crop")
print("press 2 for square padding ")
print("press 3 for grayscale")
print("press 4 for crop2")
print("press 5 for exit")
a=int(input("Your choice: "))
if a==1:
print ("The size of the Original Image is: ")
print(myim.format, myim.size, myim.mode)
print("cropping image")
crop_img()
if a==2:
print("Sqaure padding")
squae_padding()
if a==3:
print("grayscale")
gray()
if a==4:
centrecrop()
In [6]:
import cv2
In [ ]: