aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-07-08 13:46:08 +0300
committerGitHub <noreply@github.com>2023-07-08 13:46:08 +0300
commit2151a9881f3fbb0de52dbfdc83a4dd67cdfbbda6 (patch)
tree90b126bc5f52bda6d57753e4de1d18b6b8166f4b
parent19772c3c97647bdda76cd7f652ae517840431e88 (diff)
parentfb661e089f24a3056b9724c580e3badc214467cc (diff)
Merge pull request #11492 from semjon00/dev
Fix throwing exception when trying to resize image with I;16 mode
-rw-r--r--modules/images.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/images.py b/modules/images.py
index 04f55f14..cdfa6719 100644
--- a/modules/images.py
+++ b/modules/images.py
@@ -649,12 +649,18 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
oversize = image.width > opts.target_side_length or image.height > opts.target_side_length
if opts.export_for_4chan and (oversize or os.stat(fullfn).st_size > opts.img_downscale_threshold * 1024 * 1024):
ratio = image.width / image.height
-
+ resize_to = None
if oversize and ratio > 1:
- image = image.resize((round(opts.target_side_length), round(image.height * opts.target_side_length / image.width)), LANCZOS)
+ resize_to = round(opts.target_side_length), round(image.height * opts.target_side_length / image.width)
elif oversize:
- image = image.resize((round(image.width * opts.target_side_length / image.height), round(opts.target_side_length)), LANCZOS)
+ resize_to = round(image.width * opts.target_side_length / image.height), round(opts.target_side_length)
+ if resize_to is not None:
+ try:
+ # Resizing image with LANCZOS could throw an exception if e.g. image mode is I;16
+ image = image.resize(resize_to, LANCZOS)
+ except:
+ image = image.resize(resize_to)
try:
_atomically_save_image(image, fullfn_without_extension, ".jpg")
except Exception as e: