in reply to Image size in pure perl

That's neato, but <hat type="merlyn"> Yeah, CPAN already has that ;) </hat> and it is called Image::Size
SYNOPSIS use Image::Size; # Get the size of globe.gif ($globe_x, $globe_y) = imgsize("globe.gif"); # Assume X=60 and Y=40 for remaining examples use Image::Size 'html_imgsize'; # Get the size as 'width="X" height="Y"' for HTML generation $size = html_imgsize("globe.gif"); # $size == 'width="60" height="40"' use Image::Size 'attr_imgsize'; # Get the size as a list passable to routines in CGI.pm @attrs = attr_imgsize("globe.gif"); # @attrs == ('-width', 60, '-height', 40) use Image::Size; # Get the size of an in-memory buffer ($buf_x, $buf_y) = imgsize(\$buf); # Assuming that $buf was the data, imgsize() needed a referenc +e to a scalar


MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Image size in pure perl
by belg4mit (Prior) on Mar 06, 2003 at 16:34 UTC
    It's also called Image::Info

    --
    I'm not belgian but I play one on TV.

Re: Re: Image size in pure perl
by tachyon (Chancellor) on Mar 07, 2003 at 00:34 UTC

    Image::Size requires Image::Magic which in its turn require the libmagic libraries so this is not a pure Perl solution, nor is it nearly as portable. You can depend on having pack and unpack

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      No it doesn't. Please examine the Makefile.PL and the documentation.
      Recognized Formats Image::Size natively understands and sizes data in the following formats:
      GIF 
      JPG 
      XBM 
      XPM 
      PPM family (PPM/PGM/PBM) 
      XV thumbnails 
      PNG 
      MNG 
      TIF 
      BMP 
      PSD (Adobe PhotoShop) 
      SWF (ShockWave/Flash) 
      PCD (Kodak PhotoCD, see notes below) 
      
      Additionally, if the Image::Magick module is present, the file types supported by it are also supported by Image::Size. See also "CAVEATS".
      There is a reason I am PodMaster ;D
      # NOTE: Derived from blib\lib\Image\Size.pm. # Changes made here will be lost when autosplit is run again. # See AutoSplit.pm. package Image::Size; #line 741 "blib\lib\Image\Size.pm (autosplit into blib\lib\auto\Image\ +Size\pngsize.al)" # pngsize : gets the width & height (in pixels) of a png file # cor this program is on the cutting edge of technology! (pity it's bl +unt!) # # Re-written and tested by tmetro@vl.com sub pngsize { my $stream = shift; my ($x, $y, $id) = (undef, undef, "could not determine PNG size"); my ($offset, $length); # Offset to first Chunk Type code = 8-byte ident + 4-byte chunk le +ngth + 1 $offset = 12; $length = 4; if (&$read_in($stream, $length, $offset) eq 'IHDR') { # IHDR = Image Header $length = 8; ($x, $y) = unpack("NN", &$read_in($stream, $length)); $id = 'PNG'; } ($x, $y, $id); } # end of Image::Size::pngsize 1;


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
      ** The Third rule of perl club is a statement of fact: pod is sexy.