top of page

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")

画像一括リサイズは意外と簡単にできちゃいます。

 
 
 

最新記事

すべて表示
PythonでYAHOO検索もスクレイピング

前回Google検索結果のTOP100取ったのでYAHOOも追加。 YAHOOは10件ずつしか取れないので注意! #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 指定のURLをブラウザで開く #...

 
 
 
Pythonで指定URL開く&HTML解析

指定URLをブラウザで開き、その中身(HTML)を取得して表示する。 #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 指定のURLをブラウザで開く import webbrowser as wb import...

 
 
 

Comments

Couldn’t Load Comments
It looks like there was a technical problem. Try reconnecting or refreshing the page.
記事: Blog2_Post

©2021 by 日々Python。Wix.com で作成されました。

bottom of page