Beispiel #1
0
def thumbnail(image, width, height):
    img = pilimage.open(image)
    exif = None
    if 'exif' in img.info:
        exif = img.info['exif']
    img.thumbnail((width, height))
    img = img.convert("RGB")
    output = BytesIO()

    if exif:
        img.save(output, format='JPEG', exif=exif, quality=90)
    else:
        img.save(output, format='JPEG', quality=90)

    output.seek(0)
    return InMemoryUploadedFile(output, 'ImageField', "%s" % image.name,
                                'image/jpeg',
                                output.getbuffer().nbytes, None)
Beispiel #2
0
def resize(image, width, height):
    img = pilimage.open(image)
    exif = None
    if 'exif' in img.info:
        exif = img.info['exif']
    img = img.crop(correct_aspect(img, width, height))
    img = img.resize((width, height), PIL.Image.ANTIALIAS)
    img = img.convert("RGB")
    output = BytesIO()

    if exif:
        img.save(output, format='JPEG', exif=exif, quality=90)
    else:
        img.save(output, format='JPEG', quality=90)

    output.seek(0)
    return InMemoryUploadedFile(output, 'ImageField', "%s" % image.name,
                                'image/jpeg',
                                output.getbuffer().nbytes, None)