accept PNGs that have broken CRC32 checksums for ancillary chunks, which is apparently a thing we need to deal with???

This commit is contained in:
xenofem 2024-04-14 18:56:19 -04:00
parent 21c6e11228
commit 987f427c56

View file

@ -22,7 +22,8 @@ import zipfile
import dlsite_async
import fitz
from libsixel import *
from PIL import Image
from PIL import Image, UnidentifiedImageError
import PIL.ImageFile
from jinja2 import Environment, PackageLoader, select_autoescape
import pyuca
import rarfile
@ -918,8 +919,17 @@ def descendant_files_ignore(path, exclude):
return result
def standalone_image_size(filepath):
with Image.open(filepath) as im:
return im.size
try:
with Image.open(filepath) as im:
return im.size
except UnidentifiedImageError:
print(f'Warning: PIL failed to load image {filepath}! Retrying with less strict settings')
PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True
try:
with Image.open(filepath) as im:
return im.size
finally:
PIL.ImageFile.LOAD_TRUNCATED_IMAGES = False
def pdf_image_sizes(filepath):
sizes_by_xref = {}