Browse Source

Merge pull request #757 from jar1karp/better-figures-and-images-default-to-100pct-width

[better_figures_and_images] Default to 100% width if opening image with PIL fails (e.g. for SVG images)
Justin Mayer 8 years ago
parent
commit
b2c93be183
1 changed files with 6 additions and 2 deletions
  1. 6 2
      better_figures_and_images/better_figures_and_images.py

+ 6 - 2
better_figures_and_images/better_figures_and_images.py

@@ -77,8 +77,12 @@ def content_object_init(instance):
                 logger.debug('Better Fig. src: %s', src)
 
                 # Open the source image and query dimensions; build style string
-                im = Image.open(src)
-                extra_style = 'width: {}px; height: auto;'.format(im.size[0])
+                try:
+                    im = Image.open(src)
+                    extra_style = 'width: {}px; height: auto;'.format(im.size[0])
+                except IOError as e:
+                    logger.debug('Better Fig. Failed to open: %s', src)
+                    extra_style = 'width: 100%; height: auto;'
 
                 if 'RESPONSIVE_IMAGES' in instance.settings and instance.settings['RESPONSIVE_IMAGES']:
                     extra_style += ' max-width: 100%;'