4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PillowでマルチページTIFFを分割する

Posted at

前置き

マルチページのTIFF画像の各ページにアクセス、分割して保存する方法のメモ。

コード

各ページを保存する例。

from PIL import Image, ImageSequence

img = Image.open('sample.tiff')

for i, page in enumerate(ImageSequence.Iterator(img)):
    page.save("image_file_{}.jpg".format(i), format='jpeg', quality=95)

image_file_0.jpgという形式で連番のファイルが作成される。

ImageSequenceを使わない場合はtry-except構文でseek(i)を実行してEOFErrorという例外をトラップする。

まあ素直にImageSequence使うべし。

そのほか

ファイルに書き出したくないときはio.BytesIO()と組み合わせればいけるはず。

ネタ元

Python PIL For Loop to work with Multi-image TIFF - Stack Overflow

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?