Python向け画像処理モジュール「Pillow」の使い方についてサンプルコード付きでまとめました。
【はじめに】Pillowとは
Pillowとは、Python の画像処理ライブラリです。
PIL(Python Imaging Library)という開発が停止された画像処理モジュールのfork版です。
【Pillow】基本操作編
Image.open()で画像ファイルを読み込みます。
# -*- coding:utf-8 -*- from PIL import Image # 入力画像の読み込み img = Image.open("input.jpg") # 規定のソフトで画像を閲覧 img.show()
size属性で画像サイズ(幅・高さ)を取得できます。
# -*- coding:utf-8 -*- from PIL import Image # 入力画像の読み込み img = Image.open("input.jpg") width, height = img.size # 画像の幅を表示 print('width:', width) # 画像の高さを表示 print('height:',height)
【Pillow】応用編
– | 関連ページ |
---|---|
基礎 | ■Python入門 基礎文法とサンプル集 |
参考文献 | ■PIL/Pillow チートシート |
コメント