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

[MacPerl] GIF file comments



Stephane Jose <jose.stephane@uqam.ca> asks:

>That would allow me to store in the gif file things like its size in
>pixels, a description/copyright notice or even a map definition...
>
>I am stuck on the extracting part of the script. Is there a way to do this
>in MacPerl. Would it be a Mac-only solution or a 'portable-to-unix' one?

Well, it could be done quite portably.  I should point out first of all 
that if you're reading the GIF itself already, accessing its size in 
pixels is trivial.  I cribbed this (ugly) code from CPAN somewhere:

sub GifChk {
   open(GIF, $_[0]) || die "Can't open $_[0]\n";
   seek(GIF,6,0);
   read(GIF,$d,4);
   return ($w, $h) = (
      ($e = unpack("c2", pack("s", 1))) == 1
      ? unpack("s2", $d)
      : unpack("v2", $d)
   );
}

The idea of storing a map definition is kind of cute.  And a copyright 
notice might be a wise idea if you're worried about your images being 
stolen.

It doesn't look too hard to parse GIF;  the format is a series of blocks 
with block size preceding each, and a comment is just another block.  (To 
be precise, and just to make things trickier, any number of comments is 
allowed.)  The GIF file format is at:

<http://www.graphcomp.com/info/specs/gif.html>

You'll want to look at the specs for GIF89a.  I'll be happy to write the 
code for you at $60/hr :-)

I found that URL on the Internet Spec List, by the way, which I just 
stumbled across and which looks terribly useful.  
<http://www.graphcomp.com/info/specs/>

--
 Jamie McCarthy          http://www.absence.prismatix.com/jamie/
 jamie@voyager.net        Co-Webmaster of http://www.nizkor.org/