MADAO
試行錯誤で決めた解決方法は
「入れる前に修正する」
「入れる前に修正する」
MADAO
で、これを作ってみた
(めっちゃ時間かかった)
(めっちゃ時間かかった)
MADAO
これがコードだ
from PIL import Image import glob, shutil, pathlib, os, sys, random search_path = pathlib.Path(input("Adress:")) getimgpath = list(search_path.glob("**/*")) try: os.mkdir("./6234d46436K4363JHI43F423G2Y2323QQ342353627") except: pass dummy_file_name = random.randint(000000000000, 999999999999) os.mkdir(f"./6234d46436K4363JHI43F423G2Y2323QQ342353627/{dummy_file_name}") def reorient_image(im): try: image_exif = im._getexif() image_orientation = image_exif[274] if image_orientation in (2,'2'): return im.transpose(Image.FLIP_LEFT_RIGHT) elif image_orientation in (3,'3'): return im.transpose(Image.ROTATE_180) elif image_orientation in (4,'4'): return im.transpose(Image.FLIP_TOP_BOTTOM) elif image_orientation in (5,'5'): return im.transpose(Image.ROTATE_90).transpose(Image.FLIP_TOP_BOTTOM) elif image_orientation in (6,'6'): return im.transpose(Image.ROTATE_270) elif image_orientation in (7,'7'): return im.transpose(Image.ROTATE_270).transpose(Image.FLIP_TOP_BOTTOM) elif image_orientation in (8,'8'): return im.transpose(Image.ROTATE_90) else: return im except (KeyError, AttributeError, TypeError, IndexError): return im for i in getimgpath: suffix_value = pathlib.Path(i).suffix if suffix_value in (".jpg", ".png", ".bmp"): try: img_temp = Image.open(i) img_temp_rotate = reorient_image(img_temp) img_temp_rotate.save(f"./6234d46436K4363JHI43F423G2Y2323QQ342353627/img{suffix_value}") shutil.copy(f"./6234d46436K4363JHI43F423G2Y2323QQ342353627/img{suffix_value}", i) print(i) except: pass else: pass shutil.rmtree("./6234d46436K4363JHI43F423G2Y2323QQ342353627")
Comment