我想使用魔杖调整大小并优化png和jpg图像大小.
使用PIL,如果指定优化选项,我可以以大约3倍的大小保存相同的图像.
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(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或PIL的完全新手.
任何帮助/指针将不胜感激.