Created
May 13, 2016 11:03
-
-
Save awbacker/90c895cb1f66a7bd62141ea9a3cfec5c to your computer and use it in GitHub Desktop.
Crash PIL with single bit TIFF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -* | |
from __future__ import print_function, absolute_import, unicode_literals | |
import six | |
from PIL import Image | |
from django.core.files.uploadedfile import SimpleUploadedFile | |
Image.DEBUG = True | |
with open("/Users/andrew/Desktop/sample.tiff", 'rb') as f: | |
uploaded_file = SimpleUploadedFile("sample.tiff", f.read()) | |
img = Image.open(uploaded_file) | |
img.thumbnail((2000, 2000)) | |
img_io = six.BytesIO() | |
img.save(img_io, format="PNG", optimize=True) | |
img_io.seek(0) | |
f = open("/Users/andrew/Desktop/sample.png", "w") | |
f.write(img_io.read()) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment