#!/usr/bin/env python
img_obj=raw_input("")
image = Image.open(img_obj, 'r')
for pic_size_name, pic_size_val in pic_sizes.items():
    width, height = [int(item) for item in pic_size_val.split('x')]
    img_width, img_height = image.size
    pic_save_path = os.path.join(
                        save_path,
                        hash_val + '_' + pic_size_name + '.jpg'
                        )

    if image.mode not in ('L', 'RGB'):
        image = image.convert('RGBA')

    if width > img_width and height > img_height:
        image.save(pic_save_path, "jpeg", quality=90)
        continue

    img = image.copy()
    if pic_size_name == 's' or pic_size_name == 'xs':
        dest_ratio = float(width) / height
        current_ratio = float(img_width) / img_height
        if dest_ratio > current_ratio:
            offset = int((img_height - img_width / dest_ratio) / 2)
            box = (0, offset, img_width, img_height - offset)
        else:
            offset = int((img_width - img_height * dest_ratio) / 2)
            box = (offset, 0, img_width - offset, img_height)
        img = img.crop(box)
        img = img.resize((width, height), Image.ANTIALIAS)
        img.save(pic_save_path, "jpeg", quality=90)
    elif pic_size_name == 'm':
        new_height = img_height * width / img_width
        img = img.resize((width, new_height), Image.ANTIALIAS)
        img.save(pic_save_path, "jpeg", quality=90)
    else:
        img.thumbnail((width, height), Image.ANTIALIAS)
        img.save(pic_save_path, "jpeg")

