imagemagick: $ magick identify -ping <file>
reads as little as possible of a file and dumps a few basic properties of the picture file. discussion: https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=18042
you can run and read that using python's subprocess module. check_output()
is probably most useful here.
I've just tried that on a 5 GB TIFF file and it runs in no time at all.
you will have to interpret that line somewhat. it says here "8-bit sRGB", which would imply three channels. sRGB is an RGB color space.
you can pass -format ...
and a format string to get custom output.
imagemagick has a command line interface but I hear it also has APIs you can call from python. other answer with details on that: Can I access ImageMagick API with Python?
if that's unsuitable you will need to use specific libraries (libjpeg, libpng, libtiff, ...)