Skip to content

Instantly share code, notes, and snippets.

@chris-zh
Last active March 15, 2016 05:24
Show Gist options
  • Save chris-zh/1813a36bc39cb052e713 to your computer and use it in GitHub Desktop.
Save chris-zh/1813a36bc39cb052e713 to your computer and use it in GitHub Desktop.
支持Python3的图片处理库
#[Pillow说明文档][1]
#[1]:https://pillow.readthedocs.org/en/3.1.x/
#压缩图片尺寸
from __future__ import print_function
import os, sys
from PIL import Image
size = (128, 128)
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, "JPEG")
except IOError:
print("cannot create thumbnail for", infile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment