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)
新闻热点
疑难解答
图片精选