python生成指定尺寸的缩略图
width, height = im.size
if width == height:
region = im
else:
if width > height:
delta = (width - height)/2
box = (delta, 0, delta+height, height)
else:
delta = (height - width)/2
box = (0, delta, width, delta+width)
region = im.crop(box)
for size in sizes:
filename = base + "_" + "%sx%s" % (str(size), str(size)) + ".jpg"
thumb = region.resize((size,size), image.antialias)
thumb.save(filename, quality=100) # 默认 jpeg 保存质量是 75, 不太清楚。可选值(0~100)
如对本文有疑问, 点击进行留言回复!!
网友评论