Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is data stored in an image file

Tags:

image

I'm interested on a low level how image data is stored. For example, one can pull up an image in Windows and get information about the image (Camera used, date etc).

On a general level (I'm sure png, jpeg etc differ) do images have some type of header section where properties are defined, and possibly a body section that specifies the color for a specific pixel via a multidimensional array?

What might an image source look like if you could view the source similar to a webpage? If I open up a JPEG on my computer the first few lines look like XML.

like image 560
The Muffin Man Avatar asked Aug 28 '12 21:08

The Muffin Man


1 Answers

The XML you are seeing is part of the Exchangeable image file format (or Exif). If you look at the file in a Hex editor you should see markers like these:

Every JPEG file starts from binary value '0xFFD8', ends by binary value '0xFFD9'. There are several binary 0xFFXX data in JPEG data, they are called as "Marker", and it means the period of JPEG information data. 0xFFD8 means SOI(Start of image), 0xFFD9 means EOI(End of image).

A PNG file will always start with these eight bytes: 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A. It then has a similar mechanism to JPEG of using byte markers to indicate sections of data. Read the full specification here.

like image 137
robertc Avatar answered Oct 09 '22 23:10

robertc