python Pillowを使って画像を表示する

python Pillowを使って画像を表示する

pythonで、ライブラリPillow(PIL)のshowを使用して、画像を表示するサンプルコードを記述してます。pythonのバージョンは3.8.5を使用してます。

環境

  • OS windows10 pro 64bit
  • python 3.8.5

Pillowインストール

Pillowをインストールされていない方は、pipでインストールしておきます。

pip install Pillow

# Successfully installed Pillow-8.0.1

show使い方

showを使用すると、指定した画像を表示することが可能です。

from PIL import Image

image = Image.open('画像パス')
image.show()

以下は、「logo.png」という画像データを、Pillow(PIL)のshowを使用して、表示するサンプルコードとなります。

from PIL import Image

image = Image.open('logo.png')
image.show()

実行結果