拍爱

thumbnail_utils.py 401B

123456789101112131415161718
  1. # -*- coding: utf-8 -*-
  2. from __future__ import division
  3. try:
  4. from PIL import Image
  5. except ImportError:
  6. import Image
  7. def make_thumb(im_path, max_width=360):
  8. im = Image.open(im_path)
  9. width, height = im.size
  10. thumb_width = min(max_width, width)
  11. thumb_height = height / width * thumb_width
  12. im.thumbnail((thumb_width, thumb_height))
  13. im.save(im_path, im.format or 'JPEG')