On Wed, Oct 11, 2000 at 03:54:17PM -0400, Paul Winkler wrote:
For example, take a .gif or .jpeg file and throw away all but the first (let's say) 1 kb of the file. If you try to open this truncated file with an image editor (gimp, photoshop, whatever) you'll have problems. But useful information is still stored in that first part of the file, as we can see using python and PIL. Example, on linux:
head --bytes 1000 foo.gif > foo_truncated.gif python ...
import Image test = Image.open('foo_truncated.gif', 'r') test.size (210, 210)
So in this case, we can find out that foo.gif is 210 x 210 pixels even if we only have access to the first 1 kb of the 12 kb file.
This doesn't hold true for JPEG's. A JPEG encoded image consists of a set of segments, each encoding some aspect of the image. The image dimensions can be found in the frame header segment, but this segment may be preceded by tables, comments and application specific data. These extra segments could easily take up your 1K chunk. AP press for example, uses an application specific segment to encode image metadata such as subject, caption and photographer. If you have a look at the Image dimension detection code for JPEGs you'll see that it scans for a frame header (marked by C0, C1, C2 or C3 depending on the encoding used). Once found, it extracts the width and height. More information of the JPEG file encoding format can be found at: http://www.w3.org/Graphics/JPEG/itu-t81.pdf For a GIF file, the first 10 bytes should suffice, for a PNG you need the first 24. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------