Added exception catching to the photo endpoint, for cases where conversion fails (we just had one case of RGBA to JPEG didn't work).

- Legacy-Id: 18697
This commit is contained in:
Henrik Levkowetz 2020-11-16 07:55:18 +00:00
parent 49f6f8961e
commit 23a81923aa

View file

@ -99,8 +99,11 @@ def photo(request, email_or_name):
img = Image.open(person.photo)
img = img.resize((size, img.height*size//img.width))
bytes = BytesIO()
img.save(bytes, format='JPEG')
return HttpResponse(bytes.getvalue(), content_type='image/jpg')
try:
img.save(bytes, format='JPEG')
return HttpResponse(bytes.getvalue(), content_type='image/jpg')
except OSError:
raise Http404
@role_required("Secretariat")