1.pil方法来实现,安装pil
pip install pillow
安装完后引用库:
from PIL import Image
调取图片(img.size是图片尺寸):
img = Image.open("20110102051146195.jpg")
print(img.size)
截取图片(left,upper,right,lower表示裁切的坐标左上右下,注意顺序):
cropped = img.crop((0, 0, 200, 200)) # (left, upper, right, lower) 左上,右下
Image._show(cropped)
保存图片:
cropped.save("xiuyixiacom.jpg")
完整代码:
from PIL import Image
img = Image.open("20110102051146195.jpg")
print(img.size)
cropped = img.crop((0, 0, 200, 200)) # (left, upper, right, lower) 左上,右下
Image._show(cropped)
cropped.save("xiuyixiacom.jpg")