mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-09 08:12:20 -04:00
Do not error when thumbnailing invalid files (#8236)
If a file cannot be thumbnailed for some reason (e.g. the file is empty), then catch the exception and convert it to a reasonable error message for the client.
This commit is contained in:
parent
2ea1c68249
commit
b312769c0e
5 changed files with 107 additions and 23 deletions
|
@ -15,7 +15,7 @@
|
|||
import logging
|
||||
from io import BytesIO
|
||||
|
||||
from PIL import Image as Image
|
||||
from PIL import Image
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -31,12 +31,22 @@ EXIF_TRANSPOSE_MAPPINGS = {
|
|||
}
|
||||
|
||||
|
||||
class ThumbnailError(Exception):
|
||||
"""An error occurred generating a thumbnail."""
|
||||
|
||||
|
||||
class Thumbnailer:
|
||||
|
||||
FORMATS = {"image/jpeg": "JPEG", "image/png": "PNG"}
|
||||
|
||||
def __init__(self, input_path):
|
||||
self.image = Image.open(input_path)
|
||||
try:
|
||||
self.image = Image.open(input_path)
|
||||
except OSError as e:
|
||||
# If an error occurs opening the image, a thumbnail won't be able to
|
||||
# be generated.
|
||||
raise ThumbnailError from e
|
||||
|
||||
self.width, self.height = self.image.size
|
||||
self.transpose_method = None
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue