# -*- coding: utf-8 -*-

from __future__ import division

try:
    from PIL import Image
except ImportError:
    import Image


def make_thumb(im_path, 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))
    im.save(im_path, im.format or 'JPEG')