相关文章推荐
失眠的烤红薯  ·  python qt textBrowser ...·  1 月前    · 
帅气的领带  ·  【Pyspark ...·  2 周前    · 
近视的橙子  ·  python ...·  1 周前    · 
腼腆的烈马  ·  [Anaconda]——Linux下cond ...·  4 天前    · 
眉毛粗的电梯  ·  python ...·  3 天前    · 
爽快的冰棍  ·  MySQL中 ...·  4 月前    · 
15328076128  ·  为Linux ...·  3 年前    · 

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")
  •