6

I'm using this code (Writing image metadata (EXIF/TIFF/IPTC) to image file in OS X) to read EXIF/TIFF/IPTC data from image files. It's working great, but I would also need to copy the clipping path over. It's saved to a non standard index called "Photoshop" (just like the Others are called Iptc and similar).

I can't figure out how to access this information to copy it over to a newly created NSImage. The method in the link does not seem to access any non-standard informations. Any help appreciated. Thanks

EDIT ----

Here is a sample image: http://www.mad-sharky.com/clipping_path.jpg

This one contains a clipping path, it can be verified usign this tool: http://regex.info/exif.cgi you can see the "Photoshop" section. That part contains all the data I am missing with the code I am using. (Code is the same as the link above)

Community
  • 1
  • 1
sharkyenergy
  • 3,842
  • 10
  • 46
  • 97
  • can you supply an image example. ( and your code) and also are you actually seeing the property when you NSLOG – markhunte Aug 24 '15 at 17:29
  • Done.. also added a Bounty! – sharkyenergy Aug 25 '15 at 07:16
  • I notice that that site uses exiftool ( http://www.sno.phy.queensu.ca/~phil/exiftool/ ). Which I have bundled in an app before and used NSTask to make calls to it. I can see the Photoshop tag list listed on the exiftool site. But for the life of me cannot see them in your file using the exiftool. ?? – markhunte Aug 25 '15 at 14:24
  • I have made a little progress but not being massive on clipping path data, what actual Tags in that lot are you after saves me guessing. Can you add them to you answer. as I may be getting them and not realising.. – markhunte Aug 25 '15 at 16:39
  • @markhunte i am not sure I am understanding what you are asking... – sharkyenergy Aug 27 '15 at 07:29
  • I get a lot of tags. tags are the names of the data fields. i.e slice, IPTCDigest and so on, what individual ones are you after..? because I may or may not be getting them. Please specify in your question.. – markhunte Aug 27 '15 at 08:15
  • oh, now i get it.. I would need all of them, since I would like to have the new image as similar to the original as possible. Thanks! – sharkyenergy Aug 27 '15 at 11:37
  • any news on your end? Bounty expires in about 18 hours.. would be a pitty to throw 50 pts away. – sharkyenergy Aug 31 '15 at 12:20
  • I can get most of the info using exiftool. and could use it in a NSTask. But I am not sure how usable it is. `exiftool -a -u -g1 clipping_path.jpg` and also you would have to add the exiftool folder to the project. I have not found a way of getting the 'unkown' info with native Objective - c – markhunte Aug 31 '15 at 12:34
  • I would like to avoid using external tools if possible.. :( – sharkyenergy Aug 31 '15 at 13:20
  • yep. why I did not post again. I was not happy with it and was on and off looking for an answer. – markhunte Aug 31 '15 at 13:24

1 Answers1

2

I only have an old .psd file which does not have a clipping path. But does have layers.

This quick bit of example code uses the Photoshop image properties. kCGImageProperty8BIMDictionary

 NSURL *imageFileURL = [NSURL fileURLWithPath:@"/users/username/foo.psd"];
    CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageFileURL, NULL);

    NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(imageSource, 0,
                                                                                                    NULL);

    NSDictionary *bim = properties[(__bridge id)kCGImageProperty8BIMDictionary];

     NSLog(@"bim %@",bim);

      CFRelease(imageSource);

In my Image I have some image layers:

enter image description here

The NSLog from the code above returns

imageRead[11220:452087] bim { LayerNames = ( "Layer 0", "Layer 5", "Layer 6", "Layer 4", "Layer 3", "Layer 2", "Layer 1" ); Version = 1; }

If I wanted to know all the keys I could use:

id allKeys = [bim allKeys];
     NSLog(@"allKeys %@",allKeys);

And get:

imageRead[11531:463848] allKeys ( Version, LayerNames )

I could then use:

id LayerNames = [bim objectForKey:@"LayerNames"];
 NSLog(@"LayerNames %@",LayerNames);

to get :

imageRead[11563:465657] LayerNames ( "Layer 0", "Layer 5", "Layer 6", "Layer 4", "Layer 3", "Layer 2", "Layer 1" )

Or

valueForKey:, allValues

I cannot test if a clipping path would come back unfortunately

markhunte
  • 6,805
  • 2
  • 25
  • 44
  • updated the post with a jpg that contains a clipping path, and added a Bounty for the answer. – sharkyenergy Aug 25 '15 at 07:15
  • gave you the Bounty just not to throw it away.. if you happen to find a solution please post it.. :) thanks – sharkyenergy Sep 01 '15 at 06:07
  • I wiil do, hopefully i will find an easier way of getting those fields – markhunte Sep 01 '15 at 06:11
  • stupid question. what my final goal is, is to take an existing image, and just edit a few keywords. As far as I understood, to do so I have to create a new NSImage and copy all the data over, and the problem is to access these non standard data. Now the question: would it be possible to copy over everything "as is", without having to read these entries singularely? so create a NSImage that is the exact copy of the one on the hard drive? all I need to do is to have a identical copy, with JUST a few keywords changed, without losing all the other data. – sharkyenergy Sep 02 '15 at 11:45
  • @sharkyenergy hi, have you found any solution for this issue? – sinedsem Feb 13 '17 at 23:03
  • 1
    @sharkyenergy, I did not find a way to get the info natively but looking at you previous question in these comments, that is the way I would go. Copy the image and then update the copies keywords. I assume you are coping to file so you probably do not need to create a new NSImage just use one of the APIs that will copy a file in the finder. NSFilemanager I think. And then use the Coregraphics API to change the keywords of the copy. Or use Coregraphics to copy the image via NSImage/CGImage and the save it with the new info. My assumption in all this is, copying will take along the extra data.. – markhunte Feb 16 '17 at 00:20