update image metadata with values from a csv file

Post Reply
patej
Member
Posts: 79
Joined: Sun Nov 25, 2012 12:15 pm

update image metadata with values from a csv file

Post by patej »

Hi,

I have the following situation I have tried to solve and I would like to get your advice in what would be the best(most straightforward) approach. Naturally, I would not want to take too many extra turns on the way if there is a "clean way" of doing it.



- flow gets as its input one csv file and many images whose metadata (probably an IPTC field) has a "code" as its value

- I would need to update that IPTC field with information from the csv file. I.e. the csv file has the following lines:

code;name;other;info

1234;product 1;565g;253mm

1435;product 2;300g;120mm



--> I would need to update the images' metadata so that, according to the example csv above, I would add first image's name "product 1" to the image(s) that has code "1234" as the value in a specific metadata field.



I hope I could explain this understandably... So my problem is that I'm not sure how to tackle this task.

- First I thought that I would need to convert the csv into xml and use XML Pickup to get its data, but I've run into problems when trying that and now I'm thinking that it might be a too complicated approach. I've tried to get it work with the help of this thread http://www.crossroads-world.com/en/Home ... osts&t=184 but I'm using a mac and haven't managed to successfully run the c2x-cmd through an applescript element. I run into "illegal option '-sep:'" and "illegal option '-m:'" errors with it all the time.

- I'm thinking that there might be an easier way possibly via scripting since I only need that one value from the csv to be inserted into existing metadata in each image, but I'm not sure how to do it.

- I also tried the opaque pickup but that's not meant for this type of thing (I think...)



Any ideas on how I should continue?



Thanks,

--patrik
patej
Member
Posts: 79
Joined: Sun Nov 25, 2012 12:15 pm

update image metadata with values from a csv file

Post by patej »

patej wrote: - First I thought that I would need to convert the csv into xml and use XML Pickup to get its data, but I've run into problems when trying that and now I'm thinking that it might be a too complicated approach. I've tried to get it work with the help of this thread http://www.crossroads-world.com/en/Home ... osts&t=184 but I'm using a mac and haven't managed to successfully run the c2x-cmd through an applescript element. I run into "illegal option '-sep:'" and "illegal option '-m:'" errors with it all the time.




Since I couldn't figure out anything else, I tried to parse the csv file's contents with Applescript and build an xml file out of that. However, after saving the data as xml into the flow, Switch after a while added an extension .txt to it! The log says "Found extension '.TXT' for Mac type 'TEXT' and creator 'ttxt' of the file 'file-path-and-name.xml'" and named it "original-file-name.xml.txt" --> Why is that?



Even if I could get the file as a "real" xml I'm not sure how to continue in order to get the images' metadata changed... I just guessed I might be closer to my goal by first getting the csv into xml. Am I? :)



--patrik
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

update image metadata with values from a csv file

Post by dkelly »

Hello, I have a solution that will work. Please contact me off-forum.



In a previous post I explained how I used open source exiftool to write IPTC & EXIF metadata into TIFF, JPEG and PNG files. I have also developed a 100% Switch JS solution for converting CSV files to XML. Final step is to map the XML values to the IPTC field names.



Dwight Kelly

Apago, Inc.

dkelly@apago.com
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

update image metadata with values from a csv file

Post by freddyp »

To update the metadata of files you can use the "Inject XMP" element. This element can not only inject XMP, but also update it, and that is what you want to do. I have put a flow on the Crossroads site that illustrates how to do this. Search for XMP. It may still take a day or two before it is online because it has to go through an approval process.



When you are building a rule to update the metadata it should be straightforward enough what field you want to update. But how about the new value?



Let us assume the XML looks like this.





1234

product 1

565g

253mm





1435

product 2

300g

120mm







If you want to extract the value for the with 1435, the XPath looks like this:



/csvdata/line

Code: Select all

/info

	

	As a single-line text with variables this becomes:

	

	[Metadata.Text:Path="/csvdata/line[code='1435']/info",Dataset="Xml",Model="XML"]

	

	Adding this for the new value of the field you are updating will give you 120mm.

	

	However, the 1435 has to be variable too, but you cannot have a variable within a variable, so you will need to use a script expression instead to get the desired result:

	

	var codeNumberToUse = job.getVariableAsString("[Job.NameProper]");

	job.getVariableAsString("[Metadata.Text:Path="/csvdata/line[code='+codeNumberToUse+']/info",Dataset="Xml",Model="XML"]");

	

	In this example I have used [Job.NameProper] as the value for the code, but in your case

	that will probably be something else.
patej
Member
Posts: 79
Joined: Sun Nov 25, 2012 12:15 pm

update image metadata with values from a csv file

Post by patej »

Thanks for your help! After quite a bit of truggling I managed to reach my goal of both creating the flow I needed and also understanding Switch a lot more. :) The relations between Switch flows, different ways of scripting and using external commands either through the configurator or via scripting module were at first quite confusing mix, but now I feel much more confident in using those so there truly is light in the end of the tunnel.



Thanks again for your help,

--patrik
Post Reply