Skip to main content
Known Participant
Oct 31, 2008 3:34 PM UTC
Question

Can I automate the writing of XMP metadata into JPEG and TIFF files?

I have written an ASP.NET 3.5 website application on behalf of an annual international photographic competition. Entrants will be uploading digital photos in either JPEG or TIFF format. Ideally, I would write entrant identity and image title information into the XMP metadata for each image immediately after upload - but so far, I have failed to find any way to do this in ASP.NET.

Thousands of images are involved, so I need to find a way to automate the metadata insertion, perhaps with some sort of script that uses a text file (extracted from the SQL Server database on my website) as the source of the metadata for a batch of images. Is this the sort of task that can be done by writing a script for Bridge CS3? Are there any scripts already in existence that I could use? I am a total beginner in this area.

I use a Win XP PC, though I have a colleague who, I think, has CS3 on his Mac (running under the Leopard OS), so scripts for either platform might be usable.

David
This topic is closed to new replies. Start a new post to keep the conversation going.

104 replies

Known Participant
Nov 12, 2008 11:02 AM UTC
Paul,
Unfortunately, that gives me an error log as follows:

These documents have not been updated
=================================================================
=================================================================
~/My Documents/Visual Studio 2008/WebSites/SIEWebsite/EntryImages/C3-1261 Moray &REPLACEME Max.jpg ****Does Not Exist****
=================================================================
=================================================================
~/My Documents/Visual Studio 2008/WebSites/SIEWebsite/EntryImages/C4-1261 Lola &REPLACEME the girls.jpg ****Does Not Exist****
=================================================================
/c/Program Files/Adobe/Adobe Bridge/"C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/WebSites/SIEWebsite/EntryImages/C4-1261 Die Nieuwe Kerk ****Does Not Exist****
=================================================================
~/My Documents/Visual Studio 2008/WebSites/SIEWebsite/EntryImages/C1-1261 Moray &REPLACEME Max.jpg ****Does Not Exist****
=================================================================
Translate
Paul Riggott
Inspiring
Nov 12, 2008 10:22 AM UTC
I'am in the UK as well.
Now I know what the problem was, I checked how CS3 managed & and it changes it to & So the script has now been amended to cope with &
Here is the modified code and all the error line commented out so that the error log should be more readable.
Please could you test this version with some & in David?
There is a problem posting the code.
In the code there is REPLACEME replace this with a mp; but no space between the a and mp;



#target bridge

if( BridgeTalk.appName == "bridge" ) {

addInfo = MenuElement.create("command", "Update Entry Details", "at the end of Thumbnail");

}

addInfo .onSelect = function () {

mainTitleAuthor();

}



function mainTitleAuthor(){

var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");

if(csv != null){

var errorlog = new File("~/ErrorLog.txt");

errorlog.open('w');

errorlog.writeln("These documents have not been updated");

csv.open("r");

while(!csv.eof){

strInputLine = csv.readln();

errorlog.writeln("=================================================================");

// errorlog.writeln("Line From CSV File: " + strInputLine);

if (strInputLine.length > 3) { // Make sure it isn't a blank line

strInputLine = strInputLine.replace(/\\/g,'/'); //Change backslash to forward slash.

strInputLine = strInputLine.replace(/&/g,"&REPLACEME");

inputArray = strInputLine.split(",");

var csvFile = new File(inputArray[0]);

var title = inputArray[1];

var author = inputArray[2];

// errorlog.writeln("Ok can read file Checking if File Exists : " +decodeURI(csvFile));

if(!csvFile.exists) errorlog.writeln(decodeURI(csvFile) + " ****Does Not Exist****");

if(csvFile.exists){ //Check if file exists

item = new Thumbnail(csvFile);

md =item.synchronousMetadata;

// errorlog.writeln("File Exists" +decodeURI(csvFile) +inputArray[1]+" - " + inputArray[2]);

var result =addTitleAuthor(md,inputArray[1],inputArray[2]);

if(!result) errorlog.writeln(decodeURI(csvFile) + " Unable to apply template");

// errorlog.writeln("Back from creating/apply Template");

}

}

}

}

errorlog.close();

errorlog.execute();

}



function addTitleAuthor(metadata, Title, Author)

{

var strTmpl = "TempTmpl";

var strUser = Folder.userData.absoluteURI;

var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");

var fResult = false;



if (filTmpl.exists) filTmpl.remove();

try{

fResult = filTmpl.open("w");

}catch(e){

alert("Unable to create Template " +filTmpl +"\r"+e.message);

return;

}

try{

if (fResult){

//CS3

//filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.1-c037 46.282696, Mon Apr 02 2007 18:36:42 \">");

//CS2

filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");

filTmpl.writeln("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");

filTmpl.writeln("<rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");

filTmpl.writeln("<dc:title>");

filTmpl.writeln("<rdf:Alt>");

filTmpl.writeln("<rdf:li xml:lang=\"x-default\">"+Title+"</rdf:li>");

filTmpl.writeln("</rdf:Alt>");

filTmpl.writeln("</dc:title>");

filTmpl.writeln("<dc:creator>");

filTmpl.writeln("<rdf:Seq>");

filTmpl.writeln("<rdf:li>" + Author + "</rdf:li>");

filTmpl.writeln("</rdf:Seq>");

filTmpl.writeln("</dc:creator>");

filTmpl.writeln("</rdf:Description>");

filTmpl.writeln("</rdf:RDF>");

filTmpl.writeln("</x:xmpmeta>");

fResult = filTmpl.close();

metadata.applyMetadataTemplate(strTmpl, "replace");

} }

catch(e) {

alert("There was a problem with the Template");

fResult = false;

}

return fResult;

};

Translate
Known Participant
Nov 12, 2008 12:00 AM UTC
A quick check shows that Photoshop will let me manually add metadata containing an ampersand, so it must be a scripting issue.
Translate
Known Participant
Nov 11, 2008 11:57 PM UTC
Paul,
I think you've cracked it! All the failing images have an '&' in the metadata. Thanks for sticking with it. It's nearly midnight here in the UK, so it's time for my bed too!

David
Translate
Paul Riggott
Inspiring
Nov 11, 2008 11:52 PM UTC
David it looks as if the Metadata does NOT like "&" can you amend
"Moray & Max" to "Moray and Max" and see if that works.
Also can you check if the other documents that do not update contain "&".

Its getting late here so will carry on tomorrow.
Translate
Known Participant
Nov 11, 2008 11:42 PM UTC
I don't have a folder called C:\Program Files\Adobe\Adobe Utilities\ on my PC. However, it doesn't seem to matter, as my previous post shows that I found another way around the problem!
Translate
Known Participant
Nov 11, 2008 11:39 PM UTC
Your use of the name 'ExtendScript' seems to be the source of the confusion. I saved your template finding script and then went to File/Scripts/Browse in Photoshop and opened this file. TempTmpl.xmp is as follows:<br /><br /><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1.2-113"><br /><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><br /><rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/"><br /><dc:title><br /><rdf:Alt><br /><rdf:li xml:lang="x-default">Moray & Max</rdf:li><br /></rdf:Alt><br /></dc:title><br /><dc:creator><br /><rdf:Seq><br /><rdf:li>David Charles Anderson</rdf:li><br /></rdf:Seq><br /></dc:creator><br /></rdf:Description><br /></rdf:RDF><br /></x:xmpmeta>
Translate
Paul Riggott
Inspiring
Nov 11, 2008 11:36 PM UTC
It should be in..
C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit
Translate
Known Participant
Nov 11, 2008 11:33 PM UTC
Where exactly do I find this ExtendScript Toolkit?

It's not mentioned in the index of the Photoshop CS2 online help. I also checked the two 'Resources and extras' CDs that came with CS2. Do I perhaps have to reinstall Photoshop to get the option to install this feature?
Translate
Paul Riggott
Inspiring
Nov 11, 2008 11:17 PM UTC
To open the relevant folder you can run the following code from "ExtendScript Toolkit" (This comes with Photoshop).

#target bridge
var filTmpl = new Folder(Folder.userData.absoluteURI + "/Adobe/XMP/Metadata Templates/");
filTmpl.execute();
Translate