In a similar way, a GIF file has either 'GIF87a' or 'GIF89a' the first six bytes
(depending whether it's the 1987 or the 1989 standard) followed by the screen
width (in pixels) in the next two bytes, followed by the screen height in the
two after that.
Cheers,
Rob
> -----Original Message-----
> From: Nigel Wetters [mailto:[EMAIL PROTECTED]]
> Sent: 04 September 2001 17:43
> To: [EMAIL PROTECTED]
> Subject: How to find the size of a JPEG
>
>
> I've been disecting the CPAN Image::Size module, and have found out
> some useful stuff that I wanted to share. The beginners list seemed
> an appropriate place.
>
> Here's the algorithm for finding the height and width of a JPEG (all
> nambers are hex):
>
> 1. Skip the first two bytes of the file.
> 2. Read the next four bytes
> first byte->$marker
> second byte->$code
> byte 3 and 4->$length
> 3. If ($marker != FF) Bomb! It's not a JPEG!
> 4. If ($code>=C0) and ($code<=C3) GOTO 6
> 5. Skip the next ($length-2) bytes. GOTO 2.
> 6. Read the next 5 bytes. Discard the first byte.
> The height is in the second and third byte
> The width is in the fourth and fifth byte
>
> Happy hacking!
>
> --Nigel
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]