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?
crop() To crop an image to a certain area, use the PIL function Image. crop(left, upper, right, lower) that defines the area to be cropped using two points in the coordinate system: (left, upper) and (right, lower) pixel values. Those two points unambiguously define the rectangle to be cropped.
The crop() function of the image class in Pillow requires the portion to be cropped as rectangle. The rectangle portion to be cropped from an image is specified as a four-element tuple and returns the rectangle portion of the image that has been cropped as an image Object.
You can use PIL to find rows and cols of your image that are made up purely of your border color. Using this information, you can easily determine the extents of the inlaid image. PIL again will then allow you to crop the image to remove the border.
There is a crop()
method:
w, h = yourImage.size yourImage.crop((0, 30, w, h-30)).save(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With