5

I've asked similar questions before, but have not received a definitive answer. Seems that there must be a way to simply add/modify metadata to an image without loading the image into memory, without having to deal with directly reading bits.

Seems like ways exist when using CMSampleBufferRefs, but I need to be able to do this with a regular image already saved to disk.
For instance, given a very large png at /Documents/photo.png, I want to modify its exif metadata without having to load that image.

Sergey Kuryanov
  • 6,114
  • 30
  • 52
akaru
  • 6,299
  • 9
  • 63
  • 102
  • 1
    Related: [Is there any easy way to edit jpeg marker data in-place?](http://stackoverflow.com/q/10508410/85950) – blahdiblah Aug 01 '12 at 23:23
  • 1
    Since @H2CO3 provided you with perhaps the only solution you can use (I didn't have one), please accept his answer. – David H Aug 07 '12 at 11:16
  • Please also note that if you don't accept any answer, you still won't get the bounty's value back. So it would only be a benefit for one of the answerers if you accepted one of the answers. :) –  Aug 08 '12 at 09:30

2 Answers2

9

You can use libexif - I've had success with compiling it for iOS before. With libexif, you can modify any image's EXIF metadata.

  • Sure, but does this framework load the image into memory first? – akaru Aug 01 '12 at 21:46
  • That's good. Could you provide an example of such usage with libexif? i.e. loading the metadata and writing it back to the file. – akaru Aug 01 '12 at 22:44
  • @akaru this is how I implemented EXIF metadata reading and writing in my file manager app: https://github.com/H2CO3/MyFile/blob/master/src/MFImageMetadataController.m –  Aug 01 '12 at 22:50
  • Thanks, @H2CO3, I'll look into this. If you happen to know where I can grab an iOS build or XCode project of libexif for iOS, let me know. – akaru Aug 03 '12 at 07:24
  • @akaru I don't know about one, but I think the source of libexif should compile out of the box in Xcode. –  Aug 03 '12 at 07:29
  • 3
    Btw I'd appreciate having accepted my answer if it was helpful for you :) –  Aug 03 '12 at 07:30
  • @akaru Did you manage to build libexif for iOS? I'm having difficulty doing so. – Sebastian Dwornik Oct 13 '12 at 15:33
  • @SebastianDwornik [here is](http://apt.thebigboss.org/onepackage.php?bundleid=libexif) an iOS build of libexif by me. –  Oct 13 '12 at 15:37
  • @H2CO3 Thank you. How did you built it by the way? Was it difficult? – Sebastian Dwornik Oct 13 '12 at 15:44
  • @SebastianDwornik Not difficult at all if you have experience crossing stuff. Because the Apple toolchain is not entirely GNU, the standard configure - make - make install workflow won't work, but in general I just manually patch `config.h` then compile all the c files together using a manually created Makefile. –  Oct 13 '12 at 15:52
  • And here I was thinking I could do it simply through XCode. I'm still trying to extract that .DEB file you provided. Perhaps the Makefile might be easier. ;) – Sebastian Dwornik Oct 13 '12 at 15:55
  • @SebastianDwornik I never use Xcode :) And use `dpkg -x filename.deb directory` to extract the Debian package. –  Oct 13 '12 at 15:56
  • Extracted finally just before your comment. :) – Sebastian Dwornik Oct 13 '12 at 15:58
  • @H2CO3 Just looking at the code, doesn't `[MFPictureMetadata save]` load the entire image into memory before writing the EXIF? You have a call there to `jpeg_data_load_file()` – Eric Brochu Sep 27 '13 at 18:34
  • 1
    @EricBrochu (OMG that code of mine from some 2 years ago is so horrible I can't even express. Look at that chained if-else and the superfluous local `malloc()`s, aaargh...!) Indeed, it does, but I'm not sure it's a must. In fact, I'm pretty confident that's not how it should be done. Seeing the quality of that piece of code of mine... I don't even assume I got the usage of the library right. –  Sep 27 '13 at 18:42
0

If you know how to modify the EXIF, you can modify the binary data directly from the file. Just replace in the image the binary portion with the new one. I don't know if objective-c permit this, but in ansi c should be simple. The complicate part is to identify the exact part to change.

Zelter Ady
  • 6,266
  • 12
  • 48
  • 75