def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = crop_string_to_dict(image, crop)

    crop_dimensions = [int(d * crop['ratio']) for d in crop['source']]
    cropped_image = image.crop(crop_dimensions)

    store.store_avatar(user, cropped_image)
    if source == 'tmp':
        store.store_original_avatar(user)

    return crop
Exemple #2
0
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = crop_string_to_dict(image, crop)

    crop_dimensions = [int(d * crop['ratio']) for d in crop['source']]
    cropped_image = image.crop(crop_dimensions)

    store.store_avatar(user, cropped_image)
    if source == 'tmp':
        store.store_original_avatar(user)

    return crop
Exemple #3
0
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = clean_crop(image, crop)

    min_size = max(settings.MISAGO_AVATARS_SIZES)
    if image.size[0] == min_size and image.size[0] == image.size[1]:
        cropped_image = image
    else:
        upscale = 1.0 / crop['zoom']
        cropped_image = image.crop((
            int(round(crop['x'] * upscale * -1, 0)),
            int(round(crop['y'] * upscale * -1, 0)),
            int(round((crop['x'] - min_size) * upscale * -1, 0)),
            int(round((crop['y'] - min_size) * upscale * -1, 0)),
        ))

    store.store_avatar(user, cropped_image)
    if source == 'tmp':
        store.store_original_avatar(user)

    return crop
Exemple #4
0
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = clean_crop(image, crop)

    min_size = max(settings.MISAGO_AVATARS_SIZES)
    if image.size[0] == min_size and image.size[0] == image.size[1]:
        cropped_image = image
    else:
        upscale = 1.0 / crop["zoom"]
        cropped_image = image.crop(
            (
                int(round(crop["x"] * upscale * -1, 0)),
                int(round(crop["y"] * upscale * -1, 0)),
                int(round((crop["x"] - min_size) * upscale * -1, 0)),
                int(round((crop["y"] - min_size) * upscale * -1, 0)),
            )
        )

    store.store_avatar(user, cropped_image)
    if source == "tmp":
        store.store_original_avatar(user)

    return crop