Skip to main content
Known Participant
October 31, 2008
Question

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

  • October 31, 2008
  • 91 replies
  • 11728 views
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 has been closed for replies.

91 replies

Known Participant
November 7, 2008
Paul,

Could you please look into this as well?
i "Paul's script needs to be changed to read FROM a UTF-16 file."

Thank you,
Michael
Paul Riggott
Inspiring
November 6, 2008
That is strange David. I have added an error log, that reports if a file does not exist or if it can not apply the template. This error report should automatically open when it has finished going through the csv file.



#target bridge

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

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

}

addInfo .onSelect = function () {

main();

}

main();

function main(){

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();

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

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

inputArray = strInputLine.split(",");

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

var title = inputArray[1];

var author = inputArray[2];

if(!csvFile.exists) errorlog.writeln(decodeURI(csvFile) + " does not exist");

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

item = new Thumbnail(csvFile);

md =item.synchronousMetadata;

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

if(!result) errorlog.writeln(decodeURI(csvFile) + " Unable to 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;

try

{ if (filTmpl.exists)

filTmpl.remove();

fResult = filTmpl.open("w");

if (fResult)

// CS3

{

//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");

filTmpl.remove();

} }

catch(e)

{ fResult = false; }

return fResult;

};

Known Participant
November 6, 2008
xbytor,

Do you probably mean "Paul's script needs to be changed to read FROM a UTF-16 file."?
Because that is the only format I can save. I canNOT save a CSV from the UTF-16 file.

Paul,
Would this be feasible?

Michael
Known Participant
November 6, 2008
3poulakia@adobeforums.com wrote:
>
> Do you probably mean "Paul's script needs to be changed to read FROM a UTF-16 file."?
>

Yep. Just sloppy with my grammar today :)

-X
Known Participant
November 5, 2008
Paul,
I've just tried your Bridge CS2 script. We are making progress but it's still not quite right. My test CSV file has 6 rows but the metadata updates were processed only for the files listed in row 1 and row 3. All 6 test images are in the same folder and are all my own JPEGs (derived from images taken by the same camera). Very strange.

David
Known Participant
November 5, 2008
xbytor,

I fill in the fields of my xls file with the Greek data and save it as normal. Now, when I try to save the file in csv format compatibility issues are raised. Excel prompts me to save a copy in the latest Excel format. From then on whichever combination I may have tried of saving it on a CSV file has failed. Even when I save it as a UTF-16 (this file opens up with no compatibility issues as you said), it gets completely messed up trying to save it in CSV.

What do you mean when you say "I've switched to UTF-8 for my scripts ini files". How could I do that on my Mac? Would it screw things up for me if I do something wrong?

Does anyone else have any suggestions on how to solve these issues?

Thank you in advance,
Michael
Known Participant
November 5, 2008
> Does anyone else have any suggestions on how to solve these issues?
>

Paul's script needs to be changed to read UTF-8 or UTF-16 from the csv file.

-X
Paul Riggott
Inspiring
November 5, 2008
That's nice to know X, Thank you.

David.
I have had to resort to creating a template on the fly to get things working with Bridge CS2, this seems to work on my system, lets hope it works for you.



#target bridge

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

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

}

addInfo .onSelect = function () {

main();

}

function main(){

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

if(csv != null){

csv.open("r");

while(!csv.eof){

strInputLine = csv.readln();

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

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

inputArray = strInputLine.split(",");

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

var title = inputArray[1];

var author = inputArray[2];

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

item = new Thumbnail(csvFile);

md =item.synchronousMetadata;

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

}

}

}

}

}



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;

try

{ if (filTmpl.exists)

filTmpl.remove();

fResult = filTmpl.open("w");

if (fResult)

// CS3

{

//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");

filTmpl.remove();

} }

catch(e)

{ fResult = false; }

return fResult;

};

Paul Riggott
Inspiring
November 5, 2008
3poulakia - sorry javasript can not access a xls file direct that's why a csv file is the prefered method.
Known Participant
November 5, 2008
As long as the contents of the file are Unicode and you specify UTF-8 (or UTF-16
if needed) when you open the file, you should be ok reading the file. In theory.
I've switched to UTF-8 for my scripts' ini files. It has eliminated a large
number of recurring problems for me.

As far as the filename goes, I don't have a clue.

-X
Known Participant
November 5, 2008
Hi Paul R,

Reading everyones comments on errors and double checking mine, I think my problem was NOT your script but the fact that there are GREEK characters involved on both the filenames and their relative descriptions.
Since csv and Greek do not work together well, do you think you can modify the script so it reads from an XLS and NOT a CSV file? I hope it is a minor modification. CS3 on Mac always.

Thank you in advance
3poulakia
Known Participant
November 4, 2008
Thanks, Paul. Sorry for not spotting that error earlier.
Paul Riggott
Inspiring
November 4, 2008
Yup thats the problem David, if I get a chance tomorrow I will have a try using CS2 with the original script and see if I can get that working.