BigTIFF isn't supported in all image readers, and I'd like to identify files based on their TIFF format. How can I determine whether an existing tiff file was written in the standard TIFF format, or instead uses the BigTIFF format?
BigTIFF isn't supported in all image readers, and I'd like to identify files based on their TIFF format. How can I determine whether an existing tiff file was written in the standard TIFF format, or instead uses the BigTIFF format?
The python library tifffile reads TIFF files, and one of the attributes indicates the format of the TIFF.
filename = '/path/to/filename.tif'
import tifffile
def is_bigtiff(filename):
with tifffile.TiffFile(f) as img:
return img.is_bigtiff
tifffile is just reading the first few bytes of the tiff header to determine whether it is BigTIFF, so the logic is easy to recreate without the whole library (which I just realized upon looking at the source for the library, and from which the following is drawn).
import struct
def is_bigtiff(filename):
with open(filename, 'rb') as f:
header = f.read(4)
byteorder = {b'II': '<', b'MM': '>', b'EP': '<'}[header[:2]]
version = struct.unpack(byteorder + "H", header[2:4])[0]
return version == 43
One thing you could do is just simply look at the file extension, since the TIFF spec says "don't use .tif for anything other than a TIFF 6.0 file" (my wording but it's in there).
Oh wait, the universe ignored the specification...
You didn't specify a language or toolkit, so here's some info from the file format: see http://bigtiff.org