Click here to Skip to main content
6,595,444 members and growing! (20,858 online)
Email Password   helpLost your password?
Multimedia » General Graphics » General     Intermediate

Extracting IPTC header information from JPEG images

By Christian Tratz

A sample class that manipulates information (e.g. caption, author, copyrights,...) that is stored in a JPEG file
VC6, Windows, MFC, Dev
Posted:21 Jun 2001
Updated:27 Aug 2001
Views:307,444
Bookmarked:57 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
25 votes for this article.
Popularity: 5.64 Rating: 4.03 out of 5
1 vote, 6.7%
1

2
3 votes, 20.0%
3
4 votes, 26.7%
4
7 votes, 46.7%
5

This is our sample file

The sample application

File info from Adobe Photoshop

Introduction

Until I had to write an application that extracts image information from a JPEG image, I didn't know that a JPEG file can contain various information beside the pure image information (size, colors and image data). But it can contain quite a whole lot of textual and other sort of information like copyrights, captions, keywords and other stuff.

Adobe Photoshop can be used to manipulate this information from the File->File information menu. (This is probably the right place to mention that all Photoshop information here is translated from a German copy of Photoshop and thus might not exactly match the real names of the English version).

Ok. So you can edit the data with Photoshop. But what if you would like to use this data in your own application, let's say to store the images in a database along with the extracted information? That's the task of this class. You pass a file name, and then the member variables are filled. You can even modify them and write them back to the JPEG file. However this currently only works with files that already contain IPTC information.

Decoding the file format

As I tried to develop my application I searched for a similar application to reduce my work. I didn't find one. I even had a hard time to gather information on the JPEG file format specification (without buying some books) let alone the specification on the Photoshop headers. After firing up the Hex Editor I tried to find out how the things are stored. So all the structure of the Photoshop specific headers is more or less based on some findings from some sample files. If you have found a complete specification feel free to drop me a line or post it in the comments.

The basic structure is as follows. More information on that can be found here and at The Graphics File Formats Page.

JPEG image Contents Name Description
0xFF 0xD8 SOI Start of image
Segments (see below)
0xFF 0xD9 EOI End of image

JPEG segments Description
Segment marker (2 bytes)
Segment size (2 bytes) excl. marker
Segment data

Some JPEG segment markers
Contents Name Description
0xFF 0xE0 APP0 Application marker (in every JPEG file)
0xFF 0xDB DQT Quantization Table
0xFF 0xC0 SOF0 Start of frame
0xFF 0xC4 DHT Define Huffman Table
0xFF 0xDA SOS Start of scan
0xFF 0xED APP14 This is the marker where Photoshop stores its information

The Photoshop segment

The APP14 segment is the one we are after. Here starts the non-documented area.

APP14 segment Contents Description
0xFF 0xED APP14 marker
Segment size (2 bytes) excl. marker
Photoshop 3.0\x00 Photoshop identification string
8BIM segments (see below)

A JPEG file from Photoshop has various 8BIM (I don't know the real name) headers. The one with the type 0x04 0x04 contains the textual information. The image URL is stored in a different header. That's why it is currently not supported by the demo class. Other headers contain a thumbnail image and other information.

Photoshop 6 introduced a slight variation in this header segment. Basically the 4 byte padding has been replaced by a header description text of variable length. The updated sample can now handle these files as well.

8BIM segment Description
8BIM Segment marker (4 bytes)
Segment type (2 bytes)
Zero byte padding (4 bytes)
Segment size (2 bytes excl. marker, type, padding and size)
Segment data

The 8BIM header with the text is divided by even more headers, prefixed by 0x1C 0x02. These blocks then finally contain the information. Multiple blocks with the same type (e.g. Keywords) form a list.

0x1C 0x02 segment Description
0x1C 0x02 Segment marker (2 bytes)
Segment type (1 byte)
Segment size (2 bytes excl. marker, type and size)
Segment data

The sample application

With a description of the format of the information it is easy to write an application that scans through the file and extract the interesting bytes. This is exactly what the provided sample class does.

Have fun with it!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Christian Tratz


Member
If you are not living on the edge you are wasting space Wink
Occupation: Web Developer
Location: Germany Germany

Other popular General Graphics articles:

  • A flexible charting library for .NET
    Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use.
  • CxImage
    CxImage is a C++ class to load, save, display, transform BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX, TGA, WMF, WBMP, JBG, J2K images.
  • 3D Pie Chart
    A class library for drawing 3D pie charts.
  • Barcode Image Generation Library
    This library was designed to give an easy class for developers to use when they need to generate barcode images from a string of data.
  • ImageStone
    An article on a library for image manipulation.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 78 (Total in Forum: 78) (Refresh)FirstPrevNext
GeneralVB.NET/C# Pinmemberpvatanpour4:46 4 May '09  
General8BIM format table is wrong PinmemberVidbuff3:19 28 Dec '06  
Generalnothing happen PinmemberIbrahim Hamoud11:47 11 Dec '06  
Generalthanks Pinmemberscarabée22:40 15 Nov '06  
GeneralJPEG header format Pinmember882090:00 10 Jul '06  
GeneralSave crush PinmemberArnon A7:22 19 Jan '06  
GeneralRe: Save crush PinmemberChristian Tratz22:05 2 May '06  
GeneralNew header don't work.... Pinmembergothico12:48 23 Jan '05  
GeneralIt's APP13, not APP14 PinsussPhil Harvey3:07 13 Jan '05  
GeneralProblem PinmemberAndré-perpetuo6:12 3 Sep '04  
GeneralCode Errors PinsussCodeChampion21:55 22 Mar '04  
GeneralRe: Code Errors Pinmembersaveorg5:42 17 Aug '04  
GeneralSlightly wrong - here's the real 8BIM fmt Pinmemberimagerodeo20:41 21 Feb '04  
GeneralRe: Slightly wrong - here's the real 8BIM fmt PinmemberCodeChampion22:01 22 Mar '04  
GeneralRead Header of all JPEG Pinmemberalperen18:02 10 Jan '04  
GeneralRe: Read Header of all JPEG PinmemberChristian Tratz7:16 11 Jan '04  
GeneralRe: Read Header of all JPEG Pinmemberalperen8:44 11 Jan '04  
GeneralNeed 8BIM Help Pinmemberjdoklovic7:00 24 Oct '03  
GeneralApplication Independent IPTC data extraction PinmemberPriyanka Ahuja4:31 18 Sep '03  
GeneralRe: Application Independent IPTC data extraction PinmemberChristian Tratz5:09 18 Sep '03  
GeneralRe: Application Independent IPTC data extraction PinmemberPriyanka Ahuja22:21 18 Sep '03  
GeneralRe: Application Independent IPTC data extraction PinmemberChristian Tratz23:22 18 Sep '03  
Generalhow when no iptc are still stored? Pinmemberbosie17:37 3 Sep '03  
GeneralRe: how when no iptc are still stored? PinmemberChristian Tratz21:59 3 Sep '03  
GeneralRe: how when no iptc are still stored? Pinmemberbosie23:59 3 Sep '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Aug 2001
Editor: Nishant Sivakumar
Copyright 2001 by Christian Tratz
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project