Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Updating Image metadata



Folks;

I'm trying to understand the best method of updating metadata for an image file.
To put some meat on the bones, let's say I'm trying to update the IPTCKeywords (this among several others)


After a reasonable search of the usual suspects it seems to me:

1) kMDItem et al is the domain of spotlight importers. There are already image importers and it would be imprudent to attempt to overtake their responsibilities. There is not really an API for just updating selected attributes.

2) CGImage seems to be the way to go here. What I was hoping for was a more Cocoa-ish solution, but OK...

I don't really want to muck around with the image at all. I just want to update the metadata.

If I look at ImageApp in the developer stuff it seems to me that the implementation there simply rewrites the entire image:
CGImageRef image = [self currentCGImage];
if (image==nil)
goto bail;
// Create an image destination writing to `url'
CGImageDestinationRef dest = CGImageDestinationCreateWithURL ((CFURLRef)absURL, (CFStringRef)typeName, 1, nil);
if (dest==nil)
goto bail;
// Set the image in the image destination to be `image' with
// optional properties specified in saved properties dict.
CGImageDestinationAddImage(dest, image, (CFDictionaryRef)[self saveMetaAndOpts]);


Is this because of the way the ImageApp works or is this the way it has to be done?

In the Cocoa list archives from 2 years ago I find the question below.
Posed by the inimitable Ken Ferry himself with no answer given.

Can someone spare a few words to lift the cloud from my brain?
Steve
_____________________________________
Subject: modifying image metadata without loss of quality
From: Ken Ferry <email@hidden>
Date: Tue, 5 Jul 2005 11:59:56 -0400

Is it possible, using framework methods, to edit IPTC metadata embedded in a JPEG image file without recompressing the image data?

I can read and write metadata using the ImageIO framework, but I don't see how to avoid recompression on write. Here's a snippet from my test program:


- (void)imageFile:(NSString *)imagePath setIPTCKeywords:(NSArray *) asciiKeywords
{
NSMutableDictionary *iptcDictionary = [NSDictionary dictionaryWithObject:asciiKeywords
f orKey:(NSString *)kCGImagePropertyIPTCKeywords];
NSDictionary *newImageProperties = [NSDictionary dictionaryWithObject:iptcDictionary
forKey:(NSString *)kCGImagePropertyIPTCDictionary];


NSMutableData *newImageFileData = [[NSMutableData alloc] init];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL ((CFURLRef) [NSURL fileURLWithPath:imagePath], nil);
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((CFMutableDataRef)newImageFileData,
CGImageSourceGetType(imageSource),
1,
NULL);


CGImageDestinationAddImageFromSource(imageDestination,
imageSource,
0,
(CFDictionaryRef) newImageProperties);

    if (CGImageDestinationFinalize(imageDestination))
        [newImageFileData writeToFile:imagePath atomically:YES];

    CFRelease(imageDestination);
    CFRelease(imageSource);
    [newImageFileData release];
}

-Ken




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.