Skip to content

Commit

Permalink
Accept MPO files in twitter interface
Browse files Browse the repository at this point in the history
Pillow misidentifies JPG as MPO it seems, so let's see if it works if we
just accept MPO as well..
  • Loading branch information
mhagander committed Dec 12, 2023
1 parent 0f389e8 commit a0656b5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion postgresqleu/confreg/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ def volunteer_twitter(request, urlname, token):
if 'image' in request.FILES:
t.image = request.FILES['image'].read()
# Actually validate that it loads as PNG or JPG
# XXX: Pillow issue https://github.com/python-pillow/Pillow/issues/1138 misidentifies JPG
# as MPO. So we should apparenty accept MPO as well..
try:
p = ImageFile.Parser()
p.feed(t.image)
p.close()
image = p.image
if image.format not in ('PNG', 'JPEG'):
if image.format not in ('PNG', 'JPEG', 'MPO'):
return _json_response({'error': 'Image must be PNG or JPEG, not {}'.format(image.format)})
except Exception as e:
return _json_response({'error': 'Failed to parse image'})
Expand Down

0 comments on commit a0656b5

Please sign in to comment.