Python用モジュール「Pillow」で画像の幅と高さを取得する方法についてソースコード付きでまとめました。
画像の幅と高さを取得(縦・横のサイズ)
Pythonの標準モジュール「Pillow」を用いて、画像の幅と高さを取得して表示します。
サンプルコード(Python3)
サンプルプログラムのソースコードです。
# -*- coding:utf-8 -*- from PIL import Image # 入力画像の読み込み img = Image.open("input.jpg") width, height = img.size # 画像の幅を表示 print('width:', width) # 画像の高さを表示 print('height:',height)
– | 関連記事 |
---|---|
1 | ■【Python/Pillow】画像処理入門 |
2 | ■Python入門 基本文法 |
コメント