Python PIL裁剪图像给出的高度结果不正确
输出图像为480x360结果不是480x480 但是当我把这行改成Python PIL裁剪图像给出的高度结果不正确,python,python-2.7,python-imaging-library,Python,Python 2.7,Python Imaging Library,输出图像为480x360结果不是480x480 但是当我把这行改成 import PIL from PIL import Image img = Image.open('0009_jpg.jpg') width, height = img.size #height is 720 and width is 480 if height > width: rm_height = abs(height - width) # rm_height = 240 x_offset =
import PIL
from PIL import Image
img = Image.open('0009_jpg.jpg')
width, height = img.size #height is 720 and width is 480
if height > width:
rm_height = abs(height - width) # rm_height = 240
x_offset = 0
y_offset = rm_height/2 # y_offset = 120
tall = height-rm_height # tall = 480
img_crop = img.crop((x_offset, y_offset, width, tall))
img_crop.save('crop_jpg.jpg')
输出图像为正方形480x480
这没有道理。我做错了什么。谢谢在我搜索更多信息后,请确定。现在我从这个 Chris Clarke(作者:San4ez)的回答:
导入图像
im=Image.open()
宽度、高度=im.size#获取尺寸
左=(宽度-新宽度)/2
顶部=(高度-新高度)/2
右=(宽度+新宽度)/2
底部=(高度+新高度)/2
im.裁剪((左、上、右、下))
它不高。这是底部这是怎么说的?来自克里斯·克拉克,这是说im.crop((左、上、右、下))
tall = height-rm_height/2 # tall = 600
import Image
im = Image.open(<your image>)
width, height = im.size # Get dimensions
left = (width - new_width)/2
top = (height - new_height)/2
right = (width + new_width)/2
bottom = (height + new_height)/2
im.crop((left, top, right, bottom))