diff options
author | Andre Ubuntu <goulartnogueira@gmail.com> | 2023-04-05 23:28:00 +0000 |
---|---|---|
committer | Andre Ubuntu <goulartnogueira@gmail.com> | 2023-04-05 23:28:00 +0000 |
commit | 52a8f286ef99bb5004bea2b099a7bcbb073b638f (patch) | |
tree | 3d18d29e7e1de7fa6b0fdaee8e4a6abc136ca2b0 /modules/textual_inversion | |
parent | 22bcc7be428c94e9408f589966c2040187245d81 (diff) | |
download | stable-diffusion-webui-gfx803-52a8f286ef99bb5004bea2b099a7bcbb073b638f.tar.gz stable-diffusion-webui-gfx803-52a8f286ef99bb5004bea2b099a7bcbb073b638f.tar.bz2 stable-diffusion-webui-gfx803-52a8f286ef99bb5004bea2b099a7bcbb073b638f.zip |
fix preprocess orientation
Diffstat (limited to 'modules/textual_inversion')
-rw-r--r-- | modules/textual_inversion/preprocess.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/textual_inversion/preprocess.py b/modules/textual_inversion/preprocess.py index 2239cb84..9cb98694 100644 --- a/modules/textual_inversion/preprocess.py +++ b/modules/textual_inversion/preprocess.py @@ -161,7 +161,25 @@ def preprocess_work(process_src, process_dst, process_width, process_height, pre params.subindex = 0
filename = os.path.join(src, imagefile)
try:
- img = Image.open(filename).convert("RGB")
+ img = Image.open(filename)
+ # make sure to rotate the image according to EXIF data of the original image
+ # ImageOps.exif_transpose(img) # doesn't work for some reason
+ EXIF = img._getexif()
+ # rotate the image according to the EXIF data
+ try:
+ if EXIF[274] == 3:
+ # print("Rotating image by 180 degrees")
+ img = img.rotate(180, expand=True)
+ elif EXIF[274] == 6:
+ # print("Rotating image by 270 degrees")
+ img = img.rotate(270, expand=True)
+ elif EXIF[274] == 8:
+ # print("Rotating image by 90 degrees")
+ img = img.rotate(90, expand=True)
+ except:
+ pass
+ # print("No EXIF data found for image: " + filename)
+ img = img.convert("RGB")
except Exception:
continue
|