[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] GIF image size



At 3:23 pm +0200 14.05.98, Carl Johan Berglund wrote:
>Is there a way for MacPerl to read a GIF file, and figure out the size (in
>pixels) of the graphics?

GIF is relatively easy. The size of the image is given in bytes 7-10 of the
GIF file, in low-byte, high-byte order.

    sub get_gif_size {
        my($pathname) = @_;
        my($buffer);
        open(IMAGEFILE,$pathname) ||
            die "can't open image file '$pathname': $!";
        read(IMAGEFILE,$buffer,10);
        close(IMAGEFILE);
        my($filetype,$width,$height) = unpack("a6vv",$buffer);
        die "Rats!!!! '$pathname' is not a GIF\n"
            unless ($filetype =~ /^GIF/);
        return ( $width, $height);
    }

However there's no analogously simple strategy for other image types. JPEGs
in particular do everything in their power to avoid revealing their
dimensions to the casual inquirer.

There exists a more general method for finding sizes of all known image
types, but I've forgotten exactly what it is. I believe it involves using a
module which isn't part of the standard MacPerl distribution. Chris Nandor
will be along in a moment to tell us, but in the meantime the above
function may get you started.

	A

--
angus@pobox.com                                   http://pobox.com/~angus/

             "Today is the first day of the rest of the mess."



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch