in reply to Image Size

Well, I encourage you to use modules, but you can use this functions below for JPG and GIF! I put for SWF too! :-P

To use just point the file path to the right function, like in the example. For SWF the function is good to get the Flash version!

my ($w , $h , $type , $version) = IMG_jpg_size('/tmp/splash.jpg') ; print ">> $w , $h , $type , $version\n" ; ################# # IMG_OPEN_FILE # ################# sub IMG_open_file { my ( $img_fl ) = @_ ; open(IMGSTRM, $img_fl) ; binmode( IMGSTRM ); return( \*IMGSTRM ); } ############### # IMG_READBUF # ############### sub IMG_readbuf { my $buf ; read(@_[0], $buf, @_[1]) ; return( $buf ) ; } ####### # JPG # ####### sub IMG_jpg_size { my($JPEG) = IMG_open_file(@_) ; my($done)=0; my($c1,$c2,$ch,$s,$length, $dummy)=(0,0,0,0,0,0); my($a,$b,$c,$d); if ( defined($JPEG) && ($c1 = &IMG_readbuf($JPEG,1)) && ($c2 = &IMG_readbuf($JPEG,1)) && ord($c1) == 0xFF && ord($c2) == 0xD8 ) { while (ord($ch) != 0xDA && !$done) { while (ord($ch) != 0xFF) { return('error') unless ($ch = &IMG_re +adbuf($JPEG,1)) ;} while (ord($ch) == 0xFF) { return('error') unless ($ch = &IMG_re +adbuf($JPEG,1)) ;} if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) { return('error') unless ($dummy = &IMG_readbuf($JPEG,3)) ; return('error') unless ($s = &IMG_readbuf($JPEG,4)) ; ($a,$b,$c,$d)=unpack("C"x4,$s); return ($c<<8|$d, $a<<8|$b , 'jpg'); } else { return('error') unless ($s = &IMG_readbuf($JPEG,2)) ; ($c1, $c2) = unpack("C"x2,$s); $length = $c1<<8|$c2; last if (!defined($length) || $length < 2); $dummy = &IMG_readbuf($JPEG,$length-2); } } } return ('error'); } ####### # GIF # ####### sub IMG_gif_size { my($GIF) = IMG_open_file(@_) ; my($a,$b,$c,$d)=(0,0,0,0,0); my $type = &IMG_readbuf($GIF,6) ; my $s = &IMG_readbuf($GIF,4) ; if(defined( $GIF ) && $type =~ /GIF8[7,9]a/ && length($s) == 4 ) { ($a,$b,$c,$d)=unpack("C"x4,$s); return ($b<<8|$a,$d<<8|$c,'gif', "\L$type\E"); } return ('error'); } ####### # SWF # ####### sub IMG_swf_size { my($SWF) = IMG_open_file(@_) ; my $header = &IMG_readbuf($SWF,33) ; if (defined( $SWF ) && substr($header , 0 , 3) =~ /FWS/) { sub IMG_swf_bin2int { unpack("N", pack("B32", substr("0" x 32 . sh +ift, -32))); } my $ver = IMG_swf_bin2int(unpack 'B8', substr($header, 3, 1)); my $bs = unpack 'B133', substr($header, 8, 17); my $bits = IMG_swf_bin2int(substr($bs, 0, 5)); my $x = int(IMG_swf_bin2int(substr($bs, 5+$bits, $bits))/20); my $y = int(IMG_swf_bin2int(substr($bs, 5+$bits*3, $bits))/20); return ($x, $y , 'swf' , $ver); } return ('error'); } ####### # END # ####### 1;

Graciliano M. P.
"The creativity is the expression of the liberty".