How to crop a photo?

Hello!
There is a photo. You need to trim from each side by 5%. I found the crop function, but do not fully understand how it works: how to ask (and where to get) the original dimensions of the photo by OpenCV?
July 2nd 19 at 17:46
1 answer
July 2nd 19 at 17:48
Solution
It is not necessary to shoot from a gun on sparrows.
from PIL import Image

img = Image.open("img.jpg")

w5 = (img.size[0] // 100) * 5
h5 = (img.size[1] // 100) * 5

croped = img.crop(
(
w5,
h5,
 img.size[0] - w5,
 img.size[1] - h5
)
)

croped.save("croped.jpg")

Or even easier for square images
from PIL import Image
from PIL import ImageOps

img = Image.open("img.jpg")
w5 = (img.size[0] // 100) * 5

croped = ImageOps.crop(img, w5)
croped.save("croped.jpg")

Find more questions by tags OpenCVPython