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

2
  • 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. Commented Feb 8, 2016 at 23:15
  • Possible duplicate of C-like structures in Python Commented Feb 8, 2016 at 23:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.