相关文章推荐
豪情万千的豆腐  ·  python ...·  4 天前    · 
爱看书的核桃  ·  python ...·  4 天前    · 
安静的香菇  ·  Pybel转换分子文件格式·  2 天前    · 
有腹肌的豆腐  ·  angular5 - Angular 5 ...·  1 年前    · 

python裁剪图片尺寸

在 Python 中裁剪图像尺寸可以使用 Python 图像处理库 PIL(Python Imaging Library)或者其他类似的库,如 OpenCV。

下面是使用 PIL 库裁剪图像的代码示例:

from PIL import Image
# 打开图像文件
im = Image.open("example.jpg")
# 计算裁剪区域
width, height = im.size
left = (width - new_width)/2
top = (height - new_height)/2
right = (width + new_width)/2
bottom = (height + new_height)/2
# 裁剪图像
im = im.crop((left, top, right, bottom))
# 保存裁剪后的图像
im.save("example_cropped.jpg")
  •