12345678910111213141516171819 |
- from __future__ import division
- try:
- from PIL import Image
- except ImportError:
- import Image
- def make_thumbnail(im_path, im_thumbnail_path=None, max_width=360):
- im = Image.open(im_path)
- width, height = im.size
- thumb_width = min(max_width, width)
- thumb_height = height / width * thumb_width
- im.thumbnail((thumb_width, thumb_height), Image.ANTIALIAS)
- im.save(im_thumbnail_path or im_path, im.format or 'JPEG', quality=100)
- return width, height, thumb_width, thumb_height
|