load truncated images

This commit is contained in:
j 2019-01-01 00:19:55 +01:00
parent c27ddd4170
commit fd6bba5004

View file

@ -4,7 +4,7 @@
from datetime import datetime from datetime import datetime
from io import StringIO, BytesIO from io import StringIO, BytesIO
from PIL import Image from PIL import Image, ImageFile
import base64 import base64
import hashlib import hashlib
import json import json
@ -34,6 +34,7 @@ import logging
logging.getLogger('PIL').setLevel(logging.ERROR) logging.getLogger('PIL').setLevel(logging.ERROR)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
ImageFile.LOAD_TRUNCATED_IMAGES = True
ENCODING = 'base64' ENCODING = 'base64'
def valid_olid(id): def valid_olid(id):
@ -69,6 +70,7 @@ def resize_image(data, width=None, size=None):
data = StringIO(data) data = StringIO(data)
source = Image.open(data) source = Image.open(data)
#if source.mode not in ('1', 'CMYK', 'L', 'RGB', 'RGBA', 'RGBX', 'YCbCr'): #if source.mode not in ('1', 'CMYK', 'L', 'RGB', 'RGBA', 'RGBX', 'YCbCr'):
if source.mode != 'RGB':
source = source.convert('RGB') source = source.convert('RGB')
source_width = source.size[0] source_width = source.size[0]
source_height = source.size[1] source_height = source.size[1]