http://www.cis.ohio-state.edu/hypertext/faq/usenet/graphics/fileformats-faq/part4/faq-doc-10.html Parent document is top of "Graphics File Formats FAQ (Part 4 of 4): Tips and Tricks of the Trade" Previous document is "3. How can I identify the format of a graphics file?" Next document is "III. Kudos and Assertions " ---------------------------------------------------------------------------- 4. What are the format identifiers of some popular file formats? Here are a few algorithms that you can use to determine the format of a graphics file at run-time. GIF: The first six bytes of a GIF file will be the byte pattern of 474946383761h ("GIF87a") or 474946383961h ("GIF89a"). JFIF: The first three bytes are ffd8ffh (i.e., an SOI marker followed by any marker). Do not check the fourth byte, as it will vary. JPEG: The first three bytes are ffd8ffh (i.e., an SOI marker followed by any marker). Do not check the fourth byte, as it will vary. This works with most variants of "raw JPEG" as well. PNG: The first eight bytes of all PNG files are 89504e470d0a1a0ah. SPIFF: The first three bytes are ffd8ffh (i.e., an SOI marker followed by any marker). Do not check the fourth byte, as it will vary. Sun: The first four bytes of a Sun Rasterfile are 59a66a95h. If you have accidentally read this identifier using the little-endian byte order this value will will be read as 956aa659h. TGA: The last 18 bytes of a TGA Version 2 file is the string "TRUEVISION-XFILE.\0". If this string is not present, then the file is assumed to be a TGA Version 1 file. TIFF: The first four bytes of a big-endian TIFF files are 4d4d002ah and 49492a00h for little-endian TIFF files. ---------------------------------------------------------------------------- Parent document is top of "Graphics File Formats FAQ (Part 4 of 4): Tips and Tricks of the Trade" Previous document is "3. How can I identify the format of a graphics file?" Next document is "III. Kudos and Assertions "