Re: Updating Image metadata
Re: Updating Image metadata
- Subject: Re: Updating Image metadata
- From: Ryan Britton <email@hidden>
- Date: Mon, 4 Jun 2007 10:10:00 -0700
The Cocoa-ish solution is a lot more difficult than using
CGImageSource* and CGImageDestination*.
http://developer.apple.com/documentation/GraphicsImaging/Reference/
CGImageSource/Reference/reference.html
http://developer.apple.com/documentation/GraphicsImaging/Reference/
CGImageDestination/index.html
I'd suggest creating the image source with CGImageSourceCreateWithURL
(). Then create the resulting image destination and use
CGImageDestinationAddImageFromSource() on each image in the image
source, modifying the properties as you need. By default it copies
all properties so you only need to specify ones to change or remove.
On May 30, 2007, at 10:14 PM, Steve Cronin wrote:
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:
This email sent to email@hidden
_______________________________________________
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:
This email sent to email@hidden