【发布时间】:2016-04-09 14:47:40
【问题描述】:
我想使用 wand 调整和优化 png 和 jpg 图像的大小。
使用 PIL,如果我指定优化选项,我能够以大约三分之一的大小保存相同的图像。
with open(filename, 'rb') as f:
pimage = PImage.open(f)
resized_pimage = pimage.resize((scaled_width, scaled_height), PImage.ANTIALIAS) bytes_buffer = io.BytesIO()
resized_pimage.save(bytes_buffer, format="PNG", optimize=True)
但是,我不确定 Wand 的等效选项是什么:
with default_storage.open(filename, 'rb') as f:
img = WImage(file=f)
img.resize(width=scaled_width, height=scaled_height, filter='gaussian')
with WImage(width=scaled_width, height=scaled_height) as png:
png.composite(img, top=0, left=0)
png.format = 'png'
bytes_buffer = io.BytesIO()
png.save(file=bytes_buffer)
我阅读了几篇关于 ImageMagic 图像优化的文章(例如 http://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/),但我不清楚如何在 Wand 中进行这些操作(我是 Wand 或 PIL 的新手)。
任何帮助/指针将不胜感激。
【问题讨论】:
标签: python optimization png wand