Pythonでフォルダ以下の指定フォーマットファイルを一括リサイズ
- hiro2studio
- 2021年3月24日
- 読了時間: 1分
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import os.path
from PIL import Image
#-------------------------------------------------
## main ###
#-------------------------------------------------
if __name__=='__main__':
#
path "/*"
files = glob.glob(path)
for file in files:
# 拡張子取得
root, ext = os.path.splitext(file)
# .JPGだけ表示
if ext == ".JPG":
img = Image.open(file)
# サイズ固定
img_resize = img.resize((256, 256))
img_resize.save(root+"_256.JPG")
# 縦横比固定
img_resize = img.resize((img.width//4, img.height//4))
img_resize.save(root+"_25%.JPG")
画像一括リサイズは意外と簡単にできちゃいます。
Comments