-
The
filecommand prints the dimensions for several image formats (e.g. PNG, GIF, JPEG; recent versions also PPM, WEBP), and does only read the header. -
The
identifycommand (from ImageMagick) prints lots of image information for a wide variety of images. It seems to restrain itself to reading the header portion (see comments). It also uses a unified format whichfilesadly lacks. -
exiv2gives you dimensions for many formats, including JPEG, TIFF, PNG, GIF, WEBP, even if no EXIF header present. It is unclear if it reads the whole data for that though. See the manpage of exiv2 for all supported image formats. -
head -n1will give you the dimensions for PPM, PGM formats.
For formats popular on the web, both exiv2 and identify will do the job.
Depending on the use-case you may need to write your own script that combines/parses outputs of several tools.