Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum size of JPEG metadata?

Is there a theoretical maximum to the amount of metadata (EXIF, etc) that can be incorporated in a JPEG file? I'd like to allocate a buffer that is assured to be sufficient to hold the metadata for any JPEG image without having to parse it myself.

like image 431
darrinm Avatar asked Jul 14 '10 17:07

darrinm


People also ask

What metadata is in a JPEG?

JPEG metadata consists of the data contained in marker segments in a JPEG stream. The image metadata object returned from a read describes the contents of the marker segments between the SOI marker and the EOI marker for that image.

Can metadata be stored in JPEG?

Metadata is stored in two main places: Internally – embedded in the image file, in formats such as JPEG, DNG, PNG, TIFF … Externally – outside the image file in a digital asset management system (DAM) or in a “sidecar” file (such as for XMP data) or an external news exchange format document as specified by the IPTC.

Do all JPEG images contain metadata?

A typical JPEG file contains a lot more information than just the bytes required to store image data. A JPEG file also has a lot of metadata in each file containing auxiliary information about the image. On an average, this kind of metadata occupies 16% of size of the JPEG file.

Do jpegs have EXIF data?

Unfortunately, though, the only web-friendly (in terms of size) file format that can handle EXIF is JPEG, which means that you often cannot read the data from other image formats such as GIF and PNG.


3 Answers

There is no theoretical maximum, since certain APP markers can be used multiple times (e.g. APP1 is used for both the EXIF header and also the XMP block). Also, there is nothing to prevent multiple comment blocks.

In practice the one that is much more common to result in a large header is specifically the APP2 marker being used to store the ICC color profile for the image. Since some complicated color profiles can be several megabytes, it will actually get split into many APP2 blocks (since each APP block one has a 16bit addressing limit).

like image 89
Grayson Lang Avatar answered Nov 07 '22 20:11

Grayson Lang


Each APPN data area has a length field that is 2 bytes, so 65536 would hold the biggest one. If you are just worried about the EXIF data, it would be a bit less.
http://www.fileformat.info/format/jpeg/egff.htm There are at most 16 different APPN markers in a single file. I don't think they can be repeated, so 16*65K should be the theoretical max.

like image 41
edgman Avatar answered Nov 07 '22 19:11

edgman


Wikipedia states:

Exif metadata are restricted in size to 64 kB in JPEG images because according to the specification this information must be contained within a single JPEG APP1 segment.

like image 25
gsamaras Avatar answered Nov 07 '22 19:11

gsamaras