tags:

views:

1202

answers:

4

I have to link a date and a name to some jpegs that I am including in my bundle, or possibly downloading from my own server to the Documents folder. Is there a way to extract EXIF data easily?

If so, then I will use EXIF to store this info. If not, then I will have to create a database or flat file that maps my extra data to the image file.

Keep in mind, these are not photos the iPhone has taken and is providing via UIImagePicker or from outside the sandbox. These are photos that I am including with the app or downloadig to the Docs folder myself. The important point here is ease:

Is it easier to

  • read EXIF file from my image files
  • have another file that keeps track of the image file and the associated data (could be sqlite)

Thanks!

+2  A: 

You can try using iphone-exif toolkit to extract the data. However, it's licensed GPL and if your app is commercial you'll need to negotiate a license deal. If that's not viable then you may want to go the external meta-data route.

Ramin
Would writing it from scratch be a hassle? Sounds like it. The external route isn't that bad, but I would like to be able to have one file that is self-contained rather than a database linking a bunch of files, or a pair of files (img and meta-data)...
mahboudz
Another option is to start from a different codebase and port it over -- maybe something like libexif [ http://libexif.sourceforge.net/ ].
Ramin
Only if your app is commercial and not open source. You can have an open source commercial app.
Kendall Helmstetter Gelner
Given the number of app developer who do nothing but copy apps, an open source commercial app will probably flood the app store with duplicates of my app. See the number of Apple app samples being sold as "products" from other developers.
mahboudz
+1  A: 

The actual EXIF data is stored in the form of a small TIFF file with EXIF-specific TIFF tags for information that doesn't have a home in the TIFF specification. When placed in a JPEG file (really a JFIF bitstream), it is stored in a JPEG APP1 marker which limits the total size of the EXIF data to just a bit less than 64KB.

It shouldn't be that difficult to locate the APP1 marker, confirm it contains EXIF data, and then parse out a specific collection of EXIF tags with fairly brute force coding.

One example you can look at is exiftool which does just that, and is written in Perl and open source under the same terms as Perl itself.

RBerteig
+1  A: 

If these files are purely for use in your own application and will not be reused in other tools by the user, then there is some mileage in storing your data as XML/JSON in the comment segment 0xFFFE. As mentioned before you get just short of 64k to play with.

The beauty of using the comment segment is that it should be preserved by image editing tools, is quick to access (because you do not need to traverse the IFD blocks that store EXIF data, you just read/write a text string with 4 byte type/length header) and is human readable/writable in a graphics app.

I would avoid storing the associated data in a db if practical, so that you don't risk the db becoming out of sync with the available files.

Simon
I'll have to look into this. I have no experience with JSON. On the iPhone, how do you access the comment segment? Read the file in as data and then?
mahboudz
This should help http://en.wikipedia.org/wiki/JPEG#Syntax_and_structureJpeg files are built up from a series of multiple blocks/segments. Each block starts with a 2 byte block type which in some cases is followed by a 2 byte integer giving the size of the block and some data.
Simon
What you want to do is : 1) Read in 2 bytes to see what the block type is 2) If the block type is one that has associated data, read 2 more bytes in as an integer. Then skip this number of bytes. 3) Repeat steps 1 and 2 until you read a block type of 0xFFFE (the comment segment). 4) Read in the 2 byte length. Load in that number of bytes into a string buffer.What you end up with is just a text string in whatever format you like. You don't have to use strict JSON but a string like 'Name=Bob;Gender=M;Colour=Red;' is easy to decode using NSString's componentsSeparatedByString:
Simon
In a week or two I will be starting a project where the same technique could be useful to me. When I have written it for that project, I can publish some example code for you.
Simon
A: 

Simon, did you manage to bring out some example code. Publishing it will be helpful indeed :)

erastusnjuki