This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from PIL import Image | |
import getpass | |
import glob | |
import_file = os.path.join('C:/Users',getpass.getuser(),'入力ファイル名') | |
export_file = os.path.join('C:/Users',getpass.getuser(),'入力ファイル名') | |
#リサイズ後の横幅 | |
RESIZE_X = 1280 | |
#リサイズ後の縦幅 | |
RESIZE_Y = 720 | |
#アスペクト比を保持してリサイズするかのフラグ | |
isASPECT = True | |
#リサイズ用の関数 | |
def resize(image): | |
resize_x = RESIZE_X | |
resize_y = RESIZE_X / image.width * image.height if isASPECT == True else RESIZE_Y | |
return image.resize((int(resize_x),int(resize_y))) | |
files = glob.glob(os.path.join(import_file,'*.png')) | |
for file in files: | |
#画像を開く | |
img = Image.open(file) | |
img = resize(img) | |
#画像の名前を取得 | |
basename = os.path.basename(file) | |
#指定のフォルダに画像を保存 | |
img.save(os.path.join(export_file , basename)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment