Skip to content

Commit

Permalink
Fix #2417 - Adjust image converter to handle empty buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeacom committed Oct 11, 2018
1 parent dfe75c4 commit e48548a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/avatar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import requests
from git.utils import get_user
from PIL import Image, ImageOps
from pyvips.error import Error as VipsError
from svgutils.compose import SVG, Figure, Line

AVATAR_BASE = 'assets/other/avatars/'
Expand Down Expand Up @@ -411,8 +412,11 @@ def convert_img(obj, input_fmt='svg', output_fmt='png'):
"""
try:
obj_data = obj.read()
image = pyvips.Image.new_from_buffer(obj_data, f'.{input_fmt}')
return BytesIO(image.write_to_buffer(f'.{output_fmt}'))
if obj_data:
image = pyvips.Image.new_from_buffer(obj_data, f'.{input_fmt}')
return BytesIO(image.write_to_buffer(f'.{output_fmt}'))
except VipsError:
pass
except Exception as e:
logger.error(e)
return None

0 comments on commit e48548a

Please sign in to comment.