调整图片尺寸
from PIL import Image
from PIL import ImageEnhance
targetImg = fmImg(srcimgpath, width, height)
targetImg.save(targetimgpath, "JPEG")
def fmImg(imgPath,picwidth,picheight):
targetImg = Image.open(imgPath)
targetImg = transformpic(targetImg)
targetImg = targetImg.resize((picwidth, picheight), Image.ANTIALIAS)
return targetImg
def transformpic(img):
enc2 = ImageEnhance.Contrast(img)
img = enc2.enhance(1.3)
enc = ImageEnhance.Sharpness(img)
img = enc.enhance(1.3)
return img
翻转照片
srcimg = Image.open(srcimgpath)
angle = 90
targetImg = srcimg.rotate(angle)
targetImg.save(targetimgpath, "JPEG")