I want to crop image in the way by removing first 30 rows and last 30 rows from the given image. I have searched but did not get the exact solution. Does somebody have some suggestions?
There is a crop()
method:
w, h = yourImage.size
yourImage.crop((0, 30, w, h-30)).save(...)
Parameters: box – The crop rectangle, as a (left, upper, right, lower)-tuple.
Rishav 2018-12-12 18:29
You need to import PIL (Pillow) for this. Suppose you have an image of size 1200, 1600. We will crop image from 400, 400 to 800, 800
from PIL import Image
img = Image.open("ImageName.jpg")
area = (400, 400, 800, 800)
cropped_img = img.crop(area)
cropped_img.show()
An easier way to do this is using crop from ImageOps. You can feed the number of pixels you want to crop from each side.
from PIL import ImageOps
border = (0, 30, 0, 30) # left, up, right, bottom
ImageOps.crop(img, border)