Skip to content

Commit

Permalink
Merge acb62c8 into d46f056
Browse files Browse the repository at this point in the history
  • Loading branch information
litchfield committed Apr 4, 2018
2 parents d46f056 + acb62c8 commit fcb3707
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 16 additions & 6 deletions versatileimagefield/datastructures/sizedimage.py
@@ -1,6 +1,8 @@
"""Datastructures for sizing images."""
from __future__ import unicode_literals

import warnings

from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from ..settings import (
Expand Down Expand Up @@ -142,12 +144,20 @@ def __getitem__(self, key):
if resized_storage_path and not self.storage.exists(
resized_storage_path
):
self.create_resized_image(
path_to_image=self.path_to_image,
save_path_on_storage=resized_storage_path,
width=width,
height=height
)
try:
self.create_resized_image(
path_to_image=self.path_to_image,
save_path_on_storage=resized_storage_path,
width=width,
height=height
)
except (OSError, IOError, EOFError):
# Do we really want to crash on bad imges?
if getattr(settings, 'VERSATILEIMAGEFIELD_CRASH_ON_BAD', True):
raise
# Otherwise just throw a warning
warnings.warn('Unable to resize image %s' % self.path_to_image)
return

resized_url = self.storage.url(resized_storage_path)

Expand Down
4 changes: 3 additions & 1 deletion versatileimagefield/utils.py
Expand Up @@ -213,7 +213,9 @@ def get_url_from_image_key(image_instance, image_key):
size_key = None
img_url = reduce(getattr, img_key_split, image_instance)
if size_key:
img_url = img_url[size_key].url
img_url_sized = img_url[size_key]
if img_url_sized:
img_url = img_url_sized.url
return img_url


Expand Down

0 comments on commit fcb3707

Please sign in to comment.