我编写了一个 Python 代码,它将图像的大小调整为最大 1200 x 1200 帧,同时保持纵横比。我遇到了这种情况,输入图像(1080 x 1350)为 249.8KB,而输出图像(960 x 1200)为 317.2KB。尽管optimize = True
质量保持不变,但这种情况仍在发生。我的代码如下:
from PIL import Image
from wand.image import Image as Wand
MAX_RES = 1200
photo = Image.open("input.jpg")
breadth,height = photo.size
qual = Wand(filename="input.jpg").compression_quality
if(not((breadth <= MAX_RES) and (height <= MAX_RES))):
resizeRatio = max (float(breadth)/MAX_RES, float(height)/MAX_RES)
photo = photo.resize((int(breadth/resizeRatio),int(height/resizeRatio)))
photo.save("output.jpg",optimization = True,quality=qual)
使用Image.ANTIALIAS
会进一步增加尺寸。