#!/usr/bin/perl

#  gifsize

open (OFN,">-"); # use standard output as default

if($#ARGV > -1) { # but allow redirection to a file name
  close OFN;
  open (OFN,">$ARGV[0]");
}

# print list header

print OFN sprintf("%-32s %-6s %-6s\n","Filename","Width","Height");

$w = "";
$h = "";

foreach $fn (<*.gif>) { # list all .gif files
  if ($fn =~ /\.gif/) { # redundant for now, until I figure out .jpg format
    open (FH,$fn);
    binmode FH;
    read FH,$w,6; # skip first 6 bytes
    read FH,$w,2; # width
    read FH,$h,2; # height
    close FH;
    ($wl,$wh) = unpack("CC",$w); # there is probably a more
    ($hl,$hh) = unpack("CC",$h); # elegant way to do this
    $w = $wl + ($wh * 256);
    $h = $hl + ($hh * 256);
    print OFN sprintf("%-32s %6s %6s\n",$fn,$w,$h);
  }
}

close OFN;