Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flemingm opened this issue May 24, 2020 · 9 comments
Open

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

flemingm opened this issue May 24, 2020 · 9 comments
Assignees

Comments

@flemingm
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

@robaho
Copy link
Owner

robaho commented May 25, 2020

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 robaho self-assigned this May 25, 2020
@robaho
Copy link
Owner

robaho commented May 25, 2020

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

@robaho
Copy link
Owner

robaho commented Jun 15, 2020

@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
Copy link
Contributor Author

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
Copy link
Contributor Author

flemingm commented Sep 16, 2021

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants