Version 0 of Reading BMP image dimensions

Updated 2006-09-06 05:14:26 by kpv

Keith Vetter : 2006-09-06


 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 14                                ;# Past 3 integer header fields
    binary scan [read $fin 4] i width
    binary scan [read $fin 4] i height
    close $fin

    return [list $width $height]
 }

For more BMP file format details, see BMP Dump.


see also Reading GIF image dimensions, Reading PNG image dimensions, Reading JPEG image dimensions.


Category Graphics - Category File