Skip to content

Instantly share code, notes, and snippets.

@awbacker
Created May 13, 2016 11:03
Show Gist options
  • Save awbacker/90c895cb1f66a7bd62141ea9a3cfec5c to your computer and use it in GitHub Desktop.
Save awbacker/90c895cb1f66a7bd62141ea9a3cfec5c to your computer and use it in GitHub Desktop.
Crash PIL with single bit TIFF
# -*- 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