Crop an image in the centre using PIL

后端 未结 7 1232
闹比i
闹比i 2021-01-31 03:41

How can I crop an image in the center? Because I know that the box is a 4-tuple defining the left, upper, right, and lower pixel coordinate but I don\'t know how to get these co

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 04:17

    This is the function I was looking for:

    from PIL import Image
    im = Image.open("test.jpg")
    
    crop_rectangle = (50, 50, 200, 200)
    cropped_im = im.crop(crop_rectangle)
    
    cropped_im.show()
    

    Taken from another answer

提交回复
热议问题