2

I would like to use Python to extract the dimensions of a TIFF image. That will return the width and height in pixels.

The same question was asked here

How to extract dimensions for Jpegs , Png and Gif files with python with using add in modules

The answer above does not address tiff files.

I cannot add an modules at work I need a solution that will not use any add in modules.

I have found the specifications listed here

file format of tiff

it states that Tiff header is 8 bytes long

The first two bytes are either ii or MM depending on the last 4 bytes are the Offset to the IFL(Image file directory). Its inside the IFL that contains the information related to the height and width. But the IFL can be a variable size, dependent on what is inside it. Also if there are several images. The last four bytes of the IFL will be a offset to the next IFL.

The adobe specifications for TIFF are here: tiff 6.0 version adobe - It shows an example of the tiff structure on page 20.

I was wondering if someone might have had some experience with this . I struggle to understand , how to get inside the IFL and extract the information I like

Community
  • 1
  • 1
Jack Walker
  • 238
  • 1
  • 2
  • 10
  • So, extract those bytes and interpret them, what's the problem? The `struct` standard module or `ctypes.Structure` class are stock tools to work with C structures in Python. – ivan_pozdeev Feb 08 '16 at 23:15
  • Possible duplicate of [C-like structures in Python](http://stackoverflow.com/questions/35988/c-like-structures-in-python) – ivan_pozdeev Feb 08 '16 at 23:16

0 Answers0