Page 1 of 1

Copying metadata from XMP sidecar files?

Posted: Fri Jan 12, 2018 2:15 pm
by lumigraphics
I'm writing a replacement for the JPEG Export panel and currently getting metadata copying setup. I have it working in the testing snippet below for image formats having embedded metadata, but it doesn't copy metadata from RAW files (presumably due to the sidecar file.) Trying Adobe's Bridge CC SDK samples, SnpInspectMetadata.jsx actually throws an exception on

Code: Select all

new XMPFile()
with RAW files.

Do I need to test for sidecar files and parse those? I can't find documentation or anything online about this specific problem.

Code: Select all

this.run = JPEGExport();

function JPEGExport(){
var thumbs = app.document.getSelection("psd, jpg, png, tif, gif, CR2, nef");
if(thumbs.length != 0){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var i = 0;i < thumbs.length;i++){
if(thumbs[i].spec instanceof File){
var thumb = thumbs[i];
var selectedFile = thumb.spec;
var oldXmpFile = new XMPFile(selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var oldXmp = oldXmpFile.getXMP();
var bm = new BitmapData(thumbs[i].spec);
if(bm instanceof BitmapData){
var fullName = thumbs[i].name;
var finalDotPosition = fullName.lastIndexOf(".");
if(finalDotPosition > -1){
repname = fullName.substr(0 , finalDotPosition);
}
}
var exportFilePath = thumbs[i].parent.spec + "/" + repname +"_new.jpg";
var exfile = new File(exportFilePath);
bm.exportTo(exfile);
var newthumb = exfile.spec;
var myXmpFile = new XMPFile(exfile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (myXmpFile.canPutXMP(oldXmp)){
myXmpFile.putXMP(oldXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
}

Re: Copying metadata from XMP sidecar files?

Posted: Sun Aug 23, 2020 5:11 pm
by Kukurykus

Re: Copying metadata from XMP sidecar files?

Posted: Wed Sep 30, 2020 11:57 am
by Nimakhore
Great!