|
21 | 21 | ImageOps, |
22 | 22 | ImageFile, |
23 | 23 | ) |
| 24 | +from PIL.Image import DecompressionBombError |
24 | 25 | from PySide6.QtCore import QObject, Signal, QSize |
25 | 26 | from PySide6.QtGui import QPixmap |
26 | 27 | from src.core.ts_core import PLAINTEXT_TYPES, VIDEO_TYPES, IMAGE_TYPES |
@@ -138,17 +139,22 @@ def render( |
138 | 139 | try: |
139 | 140 | # Images ======================================================= |
140 | 141 | if extension in IMAGE_TYPES: |
141 | | - image = Image.open(filepath) |
142 | | - # image = self.thumb_debug |
143 | | - if image.mode == "RGBA": |
144 | | - # logging.info(image.getchannel(3).tobytes()) |
145 | | - new_bg = Image.new("RGB", image.size, color="#1e1e1e") |
146 | | - new_bg.paste(image, mask=image.getchannel(3)) |
147 | | - image = new_bg |
148 | | - if image.mode != "RGB": |
149 | | - image = image.convert(mode="RGB") |
150 | | - |
151 | | - image = ImageOps.exif_transpose(image) |
| 142 | + try: |
| 143 | + image = Image.open(filepath) |
| 144 | + # image = self.thumb_debug |
| 145 | + if image.mode == "RGBA": |
| 146 | + # logging.info(image.getchannel(3).tobytes()) |
| 147 | + new_bg = Image.new("RGB", image.size, color="#1e1e1e") |
| 148 | + new_bg.paste(image, mask=image.getchannel(3)) |
| 149 | + image = new_bg |
| 150 | + if image.mode != "RGB": |
| 151 | + image = image.convert(mode="RGB") |
| 152 | + |
| 153 | + image = ImageOps.exif_transpose(image) |
| 154 | + except DecompressionBombError as e: |
| 155 | + logging.info( |
| 156 | + f"[ThumbRenderer][ERROR] Couldn't Render thumbnail for {filepath} (because of {e})" |
| 157 | + ) |
152 | 158 |
|
153 | 159 | # Videos ======================================================= |
154 | 160 | elif extension in VIDEO_TYPES: |
@@ -321,17 +327,22 @@ def render_big( |
321 | 327 | try: |
322 | 328 | # Images ======================================================= |
323 | 329 | if extension in IMAGE_TYPES: |
324 | | - image = Image.open(filepath) |
325 | | - # image = self.thumb_debug |
326 | | - if image.mode == "RGBA": |
327 | | - # logging.info(image.getchannel(3).tobytes()) |
328 | | - new_bg = Image.new("RGB", image.size, color="#1e1e1e") |
329 | | - new_bg.paste(image, mask=image.getchannel(3)) |
330 | | - image = new_bg |
331 | | - if image.mode != "RGB": |
332 | | - image = image.convert(mode="RGB") |
333 | | - |
334 | | - image = ImageOps.exif_transpose(image) |
| 330 | + try: |
| 331 | + image = Image.open(filepath) |
| 332 | + # image = self.thumb_debug |
| 333 | + if image.mode == "RGBA": |
| 334 | + # logging.info(image.getchannel(3).tobytes()) |
| 335 | + new_bg = Image.new("RGB", image.size, color="#1e1e1e") |
| 336 | + new_bg.paste(image, mask=image.getchannel(3)) |
| 337 | + image = new_bg |
| 338 | + if image.mode != "RGB": |
| 339 | + image = image.convert(mode="RGB") |
| 340 | + |
| 341 | + image = ImageOps.exif_transpose(image) |
| 342 | + except DecompressionBombError as e: |
| 343 | + logging.info( |
| 344 | + f"[ThumbRenderer][ERROR] Couldn't Render thumbnail for {filepath} (because of {e})" |
| 345 | + ) |
335 | 346 |
|
336 | 347 | # Videos ======================================================= |
337 | 348 | elif extension in VIDEO_TYPES: |
|
0 commit comments