proc bmpsize {fname} {
set fin [open $fname r]
fconfigure $fin -translation binary
set sig [read $fin 2]
if {$sig ne "BM"} {
close $fin
error "$fname is not a BMP file"
}
seek $fin 18 ;# Past 4 integer header fields
binary scan [read $fin 4] i width
binary scan [read $fin 4] i height
close $fin
return [list $width $height]
}AMG: The width and height are stored at offset 18, not 14. At 14 is the DIB header size, which is normally 40 bytes [1]. I updated the above code accordingly.
See also edit
- BMP Dump
- Reading GIF image dimensions
- Reading PNG image dimensions
- Reading JPEG image dimensions
- Reading image type and dimensions

