Skip to content

Commit

Permalink
fix crash on loading corrupted image by PIL
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed May 28, 2019
1 parent 9c599d7 commit 2fa0493
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sphinxcontrib/plantuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,16 @@ def _get_png_tag(self, fnames, node):

# Add physical size to assist rendering (defaults)
if not styles:
im = Image.open(outfname)
im.load()
styles.extend('%s: %s%s' % (a, w * scale / 100, 'px')
for a, w in zip(['width', 'height'], im.size))
# the image may be corrupted if platuml isn't configured correctly,
# which isn't a hard error.
try:
im = Image.open(outfname)
im.load()
styles.extend('%s: %s%s' % (a, w * scale / 100, 'px')
for a, w in zip(['width', 'height'], im.size))
except OSError as err:
logger.warning('plantuml: failed to get image size: %s'
% err)

return ('<a href="%s"><img src="%s" alt="%s" style="%s"/>'
'</a>\n'
Expand Down

0 comments on commit 2fa0493

Please sign in to comment.