Skip to content

Commit

Permalink
Adding new progressive_jpeg setting #49
Browse files Browse the repository at this point in the history
  • Loading branch information
respondcreate committed May 30, 2016
1 parent b8ff7f0 commit e836a36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion docs/installation.rst
Expand Up @@ -99,7 +99,10 @@ A dictionary that allows you to fine-tune how ``django-versatileimagefield`` wor
# just define a function (that can be imported from your project's
# python path) that takes a single argument, `image_key` and returns
# a string.
'image_key_post_processor': None
'image_key_post_processor': None,
# Whether to create progressive JPEGs. Read more about progressive JPEGs
# here: https://optimus.io/support/progressive-jpeg/
'progressive_jpeg': False
}
.. _placehold-it:
Expand Down
8 changes: 6 additions & 2 deletions versatileimagefield/datastructures/base.py
Expand Up @@ -5,7 +5,7 @@

from django.core.files.uploadedfile import InMemoryUploadedFile

from ..settings import QUAL
from ..settings import QUAL, VERSATILEIMAGEFIELD_PROGRESSIVE_JPEG
from ..utils import get_image_metadata_from_file_ext

EXIF_ORIENTATION_KEY = 274
Expand Down Expand Up @@ -127,9 +127,13 @@ def preprocess_JPEG(self, image, **kwargs):
defined by the `VERSATILEIMAGEFIELD_JPEG_RESIZE_QUALITY`
setting)
"""
save_kwargs = {
'progressive': VERSATILEIMAGEFIELD_PROGRESSIVE_JPEG,
'quality': QUAL
}
if image.mode != 'RGB':
image = image.convert('RGB')
return (image, {'quality': QUAL})
return (image, save_kwargs)

def retrieve_image(self, path_to_image):
"""Return a PIL Image instance stored at `path_to_image`."""
Expand Down
10 changes: 9 additions & 1 deletion versatileimagefield/settings.py
@@ -1,3 +1,4 @@
"""versatileimagefield settings."""
from __future__ import unicode_literals
from django.utils.module_loading import import_string

Expand Down Expand Up @@ -55,7 +56,10 @@
# just define a function (that can be imported from your project's
# python path) that takes a single argument, `image_key` and returns
# a string.
'image_key_post_processor': None
'image_key_post_processor': None,
# Whether to create progressive JPEGs. Read more about progressive JPEGs
# here: https://optimus.io/support/progressive-jpeg/
'progressive_jpeg': False
}

USER_DEFINED = getattr(
Expand Down Expand Up @@ -98,6 +102,10 @@
'create_images_on_demand'
)

VERSATILEIMAGEFIELD_PROGRESSIVE_JPEG = VERSATILEIMAGEFIELD_SETTINGS.get(
'progressive_jpeg'
)

IMAGE_SETS = getattr(settings, 'VERSATILEIMAGEFIELD_RENDITION_KEY_SETS', {})

post_processor_string = VERSATILEIMAGEFIELD_SETTINGS.get(
Expand Down

0 comments on commit e836a36

Please sign in to comment.