Hi there,
I'm trying to read Exif data from PNG files but hit a brick wall, and the lack of or poor documentation is just frustrating.
Originally I just wanted to tinker around with dithering for reducing bit-depth in pictures, and it all kind of spiralled out of control with adding support for PNG and JPEG, and now finally wanting to preserve meta-data across file formats as good as possible. ;o)
The Exif data in PNGs is stored in a "Raw profile type exif" text chunk and looks like this:
Code:
exif
5156
45786966000049492a00080000000b000001040001000000640000000101040001000000
430000000201030003000000920000000f01020009000000980000001001020005000000
a20000001a01050001000000a80000001b01050001000000b00000002801030001000000
...
which seems to be hexadecimal representation of binary data (no docs found about that).
Converting that to binary seems promising, I get a block of binary data starting with "Exif".
So I figured I could just feed that binary data to libexif, but no luck. (and again, no useful documentation)
From the little documentation found on EXIF library (libexif) API: The libexif library I expected to simply do:
Code:
ExifLoader *loader = exif_loader_new();
exif_loader_write(loader, rawdata, len);
ExifData *data = exif_loader_get_data(loader);
But no luck, just a NULL return value.
Does anybody here have any experience with this?
I stripped down the code to just the bare minimum but it's still ~300 lines, so I am attaching it instead of pasting it all in here. (along with a small sample PNG file).
Needs libexif and libpng to compile
Code:
sudo apt-get install libpng-dev libexif-dev
gcc -std=c99 pngexif.c -lpng -lexif
Thanks a bunch,
Rupert