I have a plugin that needs to copy metadata from a file and replace the metadata in another file with the exact metadata from the first file.
I can do this with batch play and it works. However, if the file that is receiving the metadata already has metadata items then some items that already exist such as camera model, date taken, etc won’t replace the existing data with the new data. Other items such as copyright and description will overwrite with the new data. For any items that don’t have data, it imports the values just fine.
The use case for this is I have a plugin that makes composite images in batch for youth school and sports photographers. The photographers will have cutout images of a player or student that are png or tif images. The software imports these images into PSD templates that contain different backgrounds and graphics. The photographers need the composited image to contain the original data from the cutout file because they are using either timestamps or scanned barcode data in metadata to link the images to students, track orders, etc. They have other systems that look for this metadata after they upload their images into the various systems.
If the PSD template they are using was created from a blank document to start with then the data can be imported OK. However, if the PSD template was created with another image file as a starting point that already contains metadata then the template has that metadata. In those cases, only certain metadata items from the cutout file will overwrite the existing metadata items. I have no control over how the templates are being created as that is done by the photographers or other graphics designers.
So what I want to attempt is to delete all metadata from the composited image before importing the new metadata that was retrieved from the cutout image. I can’t figure out if it is possible to clear al of the existing metadata or even know where to start.
When the cutout image file opens, it uses this function to get the meta data of that file.
async function getMetaData(){
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "XMPMetadataAsUTF8"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "execute"
});
return result[0].XMPMetadataAsUTF8;
}
After bringing the cutout file into the PSD template file for the composited file, before saving as a new file, the following function is used to set the metadata from the metadata the was retrieved from the cutout file. Again, this works if the metadata items are empty to start with. However, only certain items will overwrite if data already exists.
async function setMetaData(xmpString){
const batchPlay = require("photoshop").action.batchPlay;
await batchPlay(
[
{
"_obj": "set",
"_target": [
{
"_property": "XMPMetadataAsUTF8"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
to: {
_obj: "document",
XMPMetadataAsUTF8: xmpString
}
}
],{
"synchronousExecution": false,
"modalBehavior": "execute"
});
}