Skip to content

Commit

Permalink
Added support again for optimize and progressive PIL save options.
Browse files Browse the repository at this point in the history
  • Loading branch information
saulshanabrook committed May 29, 2013
1 parent e49af58 commit 4949262
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
v0.2.1, 05/29/13 -- Proper progressive and optomize support
v0.2.0, 05/29/13 -- Don't save with optomize either, also encounters same error
v0.1.9, 05/29/13 -- Don't save as progressive, because encounters errors
v0.1.8, 05/29/13 -- Convert image to JPEG colorspace and save with higher quality and progressive
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='django-simpleimages',
version='0.2.0',
version='0.2.1',
author='Saul Shanabrook',
author_email='s.shanabrook@gmail.com',
packages=['simpleimages', 'simpleimages.test'],
Expand Down
20 changes: 19 additions & 1 deletion simpleimages/transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from StringIO import StringIO
from exceptions import IOError

from PIL import Image
from PIL import Image, ImageFile

from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.files import File
Expand Down Expand Up @@ -51,6 +52,23 @@ def django_file_from_pil_image(transformed_pil_image, file_name):
temp_io = StringIO()
if transformed_pil_image.mode not in ('L', 'RGB'):
transformed_pil_image = transformed_pil_image.convert("RGB")
try:
transformed_pil_image.save(
temp_io,
"JPEG",
quality=85,
optimize=True,
progressive=True
)
except IOError:
ImageFile.MAXBLOCK = transformed_pil_image.size[0] * transformed_pil_image.size[1]
transformed_pil_image.save(
temp_io,
"JPEG",
quality=85,
optimize=True,
progressive=True
)
transformed_pil_image.save(
temp_io,
format='JPEG',
Expand Down

0 comments on commit 4949262

Please sign in to comment.