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 10, 2008
Paul,
Apologies for the delay, but I've now managed to find time to experiment with the 6 Nov version of your Bridge CS2 script. The results are exactly as before, i.e. only 2 of the 6 images in my CSV file were updated.

No error messages appeared and I can't find any ErrorLog.txt file.

David
Known Participant
November 7, 2008
I think I am on the wrong track all-together.

1. I DO have headers
2. I was looking for a script to import descriptions, title and description writer (as I mentioned on comment # 14
3. I put no path (because I thought it would not be a problem) since I placed the images in the same folder. I just wrote the images name+extension

My deepest apologies for running everyone around in circles.

Michael
Paul Riggott
Inspiring
November 7, 2008
There should be NO header if there is one it will just be reported in the error file.

Field1: FileName including Path
Field2: Title
Field3: Author
ie:
volume/folder/folder2/fileName.jpg,Title Details,Author details
Known Participant
November 7, 2008
Paul,

One last thing to try before emailing you.
Could you please tell me what exactly the names of the fields in the csv file must be?

I am using CS3 (Photoshop/Bridge/InDesign) on a MAC

Michael
Paul Riggott
Inspiring
November 7, 2008
Just another thing to try is, in your csv file make sure there is a filepath/filename that does not exist, if this does not show in the error file it means that it does not like the encoding. I tried with "UTF-16" and nothing was produced but worked ok with "UTF-8"
Paul Riggott
Inspiring
November 7, 2008
I wonder if you could email me a one line csv file, I can then try to get it working at this end Micheal?

pst DOT pmr AT googlemail DOT com

Also what version of Photoshop are you using?
Known Participant
November 7, 2008
I don't know Paul,

It returns no values what so ever

Michael
:-(
Paul Riggott
Inspiring
November 7, 2008
I got it wrong Michael! I was running it from ExtendScript Toolkit and added a main(); that ran the program.
This version should be better, and have added the UTF-16



#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){

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

errorlog.open('w');

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

csv.open("r");

csv.encoding = "UTF-16";

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 7, 2008
Hi Paul,

I did what you said but this is what happened RIGHT at opening Bridge:

Adialog box pops up asking me to choose a csv file. I of course cancel since I did not ask for the script to run. I mean the script runs by itself. It's alive. It's alive....
After that I get the following error:

i An error occured while running a startup script named xmp2jpg_tiff. It may not be compatible with this version of Bridge. You can check for available updates by selecting the updates command from the Help menu.
i The script is disabled.

i error in ......bla..bla..bla..:xmp2jpg_tiff.csv

i Line69: errorlog.close();

i undefined is not an object

Did I do something wrong?
Michael
Paul Riggott
Inspiring
November 7, 2008
Hi Micheal, all you need to do is add one line.
Find this line below
csv.open("r");
Then add this line after the above line.
csv.encoding = "UTF-16";

According to the documentation there is Greek as well, so if UTF-16 doesn't work you could try this?
csv.encoding = "X-MAC-GREEK";