Exemplo n.º 1
0
def scale_blog_image(image, size):
    size = size.split('x')
    image_path = image.path
    (root, name, ext) = split_filepath(image_path)
    filename = scale_image(image_path, (int(size[0]), int(size[1])))
    if filename:
        image_url = image.url.split('/')
        image_url[-1] = filename
        return '/'.join(image_url)
    else:
        return image.url
Exemplo n.º 2
0
def crop(image, size):
    """
    Template filter used to crop an image
    to make it fill the defined area.

    {% load image_tags %}
    {{ profile.picture|crop:"48x48" }}

    """
    size = size.split('x')
    (root, name, ext) = split_filepath(image.path)
    filename = scale_image(image.path, (int(size[0]), int(size[1])), 'crop')
    return '/%s/%s' % (os.path.abspath(root).replace('%s/' % os.path.abspath(settings.BASE_PATH), ''), filename)
Exemplo n.º 3
0
def save_temporary_blog_image(image_file):
    if not os.path.exists(settings.TEMP_BLOG_IMAGE_ROOT):
        os.makedirs(settings.TEMP_BLOG_IMAGE_ROOT)

    (root, file_name, file_ext) = split_filepath(image_file.name)

    file_name = '%s.%s' % (uuid.uuid4(), file_ext)

    destination = open('%s%s' % (settings.TEMP_BLOG_IMAGE_ROOT, file_name), 'wd+')
    for chunk in image_file.chunks():
        destination.write(chunk)
    destination.close()

    thumbnail_filename = scale_image('%s%s' % (settings.TEMP_BLOG_IMAGE_ROOT, file_name), (settings.BLOG_IMAGE_PREVIEW_WIDTH, settings.BLOG_IMAGE_PREVIEW_HEIGHT))
    thumbnail_url = '%s%s%s' % (settings.MEDIA_URL, settings.TEMP_BLOG_IMAGE_URL, thumbnail_filename)
    return file_name, thumbnail_url