robaho / seashore

easy to use mac osx image editing application for the rest of us
GNU General Public License v2.0
454 stars 20 forks source link

GPS, IPTC Metadata is not saved between edits. #131

Open flemingm opened 4 years ago

flemingm commented 4 years ago

When opening image with metadata and resaving to JPG, some of the Metadata is stripped when saving it. EXIF metadata is not stripped. BUT GPS and IPTC metadata is stripped.

Sample before saving with IPTC data: DSC_7236

Same file after saving: DSC_7236-missing IPTC

AS I am not familiar with the code, I do not know where to look to fix this. If you point me in the right direction, I will attempt to find time to fix it.

I am also willing to help add option to edit/insert IPTC metadata.

Mark

flemingm commented 4 years ago

Found the export, import and document modules... Your thought does this sound like it will work?

So implementation should be easy:

Exporter:

/Seashore/source/exporter/JPEGExporter.m

line 245: // Add EXIF data exifData = [[document contents] exifData]; if (exifData) [imageRep setProperty:@"NSImageEXIFData" withValue:exifData];

Export module will need to be upgraded to using CoreImage but with that is will support all type core image supports.

Document container Will need to save the extra metadata on import.

ie. add place to save it in Seashore/source/document/SeaContent.h

   // The metaData data associated with this image
NSDictionary * metaDataPropsData

Show how much rich metadata is accessible using core images approach: https://developer.apple.com/documentation/imageio/cgimageproperties?language=objc

I would suggest using CoreImage Metadata structure to hold all data. ie. by calling the CGImageSourceCopyPropertiesAtIndex(::_:) function)

Importing metadata Using: Seashore/source/document/CocoaContent.m Line 185:

exifData = [(NSBitmapImageRep*)imageRep valueForProperty:@"NSImageEXIFData"];

Has some limitations https://developer.apple.com/documentation/appkit/nsimageexifdata?language=objc

Changing it to use core image would be my recommendation:

mUrl = url;   
CGImageSourceRef source = NULL;

if (url) source = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL);

// CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL);
if (source) {
    // get image properties (height, width, depth, metadata etc.) for display
    metaDataPropsData = (__bridge_transfer NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
   if (props) {
       // for backwoods compatibility extra EXIF data.
    exifData = [props objectForKey: (NSString* ) kCGImagePropertyExifDictionary];
 }
}
flemingm commented 4 years ago

Writing if back:

https://stackoverflow.com/questions/19692455/writing-image-metadata-exif-tiff-iptc-to-image-file-in-os-x

robaho commented 4 years ago

Thanks Mark for the detailed report. I will see what I can do. Feel free to submit a PR as well. One thing to keep in mind, that any APIs used must be available for 10.7+ or it is a bit more work since they have to be guarded.

robaho commented 4 years ago

A quick check shows the additional metadata appears in 10.4+ so it shouldn't be a problem.

robaho commented 4 years ago

@flemingm Hi Mark, I'm curious - the EXIF standard appears to have support for GPS tags https://exiftool.org/TagNames/GPS.html - is this not sufficient ?

flemingm commented 4 years ago

Exchangeable image file format (EXIF) standard is at http://www.exif.org/Exif2-2.PDF for digital still cameras. Yes EXIF contains the GPS data from the camera. It also has some limited fields for comments. Also many of EXIF Tag are same as TIFF Rev. 6.0 Attribute Information

Search engines have started to show specific metadata fields of ITPC photos in search results next to a thumbnail of the photo. In Autumn 2018, Google introduced some new features to their image search. When an image is shown, one could have clicked on “Image Credits” and a popup will show the image’s creator, credit line and a copyright notice. From 28 May 2020 on these fields are shown instantly next to a photo, no click is required anymore. It works by reading the corresponding embedded IPTC photo metadata fields from the image file.

In Summer 2020, Google is planning to extend this feature to also display the image’s licence (what we call Web Statement of Rights) in the results of all image searches. Google will also show a link to a web page where a licence to re-use the image can be obtained – the Licensor URL.

IPTC was designed to be Open standards for the news media, see standards.

Read about it at: https://iptc.org/standards/photo-metadata/quick-guide-to-iptc-photo-metadata-and-google-images/

Mark

flemingm commented 3 years ago

started working on this in flemingm branch.

will need to update the following to export metadata.

gifExporter, jpegExporter, -- source/exporter/JPEGExporter.m jp2Exporter, pngExporter, tiffExporter, xcfExporter, heicExporter,

        // ------

// something like: // NOTE only HEIC,TIFF, PNG and JPEG support all metadata. StringRef imageType = CGImageSourceGetType(source);

NSDictionary * options = [ kCGImagePropertyOrientation: orientation, kCGImagePropertyHasAlpha: true, kCGImageDestinationLossyCompressionQuality: compressionRatio ];

//new empty data to write the final image data to NSMutableData *resultData = [NSMutableData data]; CGImageDestinationRef imgDest = CGImageDestinationCreateWithData((bridge CFMutableDataRef)(resultData), imageType, 1, nil); if (imgDest) { //copy image data. CGImageDestinationAddImageFromSource(imgDest, source, 0, (bridge CFDictionaryRef)(metaDataPropsData)); BOOL success = CGImageDestinationFinalize(imgDest); CFRelease(imgDest); } CFRelease(source); } // writing back all the metadata including EXIF, TIFF, and IPTC.

flemingm commented 3 years ago

I have a draft working implementation for reading and just test jpeg exporter -- need to clean up code in exporter then do other exporter's

flemingm commented 1 year ago

was browsing and found NSBitmapImageRep support NSImageIPTCData is support in 12.0 SO coreImage is still the way to implement this. will try to get back to is sometime this summer.