2

I have >400 JPG files and a JSON file for each which contains the image tags, description and title. I've found this command

exiftool -json=picture.json picture.jpg

But I don't want to run this for each and every file.
How can I run this command for the folder containing the JPGs and JSONs or is there another way I can batch process these?
Each JSON file has the same name as it's JPG counterpart so it's easy to identify which files match up to each other.

George Profenza
  • 50,687
  • 19
  • 144
  • 218
Raf
  • 48
  • 1
  • 6

1 Answers1

1

Assuming your JPGs and JSONs have the same filename, but different extesion(e.g. picture001.jpg has an associated picture001.json,etc.), a batch for loop might work. Assuming you've already cd-ed into the folder and the files aren't nested in folders, something like this should work

( for jpg in *.jpg; do exiftool -json=${jpg/\.jpg/.json} $jpg; done )

Note that this isn't tested. I recommend making a copy of your folder and testing there beforehand to make sure you don't irreversibly damage them.

I've also noticed you're using the java tag. I had to work with EXIF data in Java a while back (on Android then) and I used the JHeader library. If you want to roll your own little java command line tool, you should be able to use Java's IO classes to traverse your directory and files and the JHeader library to modify the EXIF data.

Community
  • 1
  • 1
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Thanks! I tried this but ran into an error, there isn't enough space in this textbox for me to copypaste it but [here's a screenshot of what I did and what happened.](http://i.imgur.com/UZl681a.png) – Raf Aug 10 '15 at 10:06
  • You didn't mention windows. My solution is in bash, you can run on unix systems. On Windows you'll need something like [cygwin](https://www.cygwin.com/) or [mingw](http://www.mingw.org/). Note that you run the script as it is, without exiftool.exe in front. At the moment I won't be able to do a DOS/batch version, but the same principles apply. The syntax will be different – George Profenza Aug 10 '15 at 10:23
  • Ah OK, sorry I forgot to say I was on Windows! Thank you, I'll download cygwin, I believe I've used that before. – Raf Aug 10 '15 at 10:43
  • cygwin wasn't working out for me so I fired up an Ubuntu VM, installed exiftool and ran your command but it's throwing back these three lines for each file Line 1: "No SourceFile entries in 'imagename.json'" Line 2: "No SourceFile 'imagename.jpg' in imported JSON database" Line 3: "(absolute path: '/media/FlickrPics/imagename.jpg')" – Raf Aug 10 '15 at 13:49
  • Sounds like the paths aren't quick right. I did a quick dummy test: added a bunch of json and jpg files```ls -l total 0 -rw-r--r-- 1 georgeprofenza staff 0 10 Aug 14:58 pic001.jpg -rw-r--r-- 1 georgeprofenza staff 0 10 Aug 14:58 pic001.json -rw-r--r-- 1 georgeprofenza staff 0 10 Aug 14:59 pic002.jpg -rw-r--r-- 1 georgeprofenza staff 0 10 Aug 14:58 pic002.json -rw-r--r-- 1 georgeprofenza staff 0 10 Aug 14:59 pic003.jpg -rw-r--r-- 1 georgeprofenza staff 0 10 Aug 14:59 pic003.json``` then ran a slightly modified version of the script which only prints data to the prompt... – George Profenza Aug 10 '15 at 14:01
  • ...but doesn't call exiftool, just to test the paths: ```( for jpg in *.jpg; do echo ${jpg/\.jpg/.json} $jpg; done )``` and it prints the expected output: ```pic001.json pic001.jpg pic002.json pic002.jpg pic003.json pic003.jpg```. Did you call ```cd /media/FlickrPics/```before running the for loop above ? – George Profenza Aug 10 '15 at 14:03
  • Yep I ran cd first. I just ran your test command, calling echo instead of exiftool, and it produced the expected result (same as yours). I then tried the command calling exiftool once more and again it did not work. Could it be something to do with the contents of the JSON files? That's all I can think of now. The content of each JSON is as follows: `{"Tags":"seperate, image, tags, here","Description":"Image description here","Title":"Image Title Here"}` – Raf Aug 10 '15 at 20:52
  • I assumed your configurations were already working since your question is about batch processing and not about using the tool itself. Have you tested with a single image and json file first ? I haven't used exiftool before. is [this](http://www.sno.phy.queensu.ca/~phil/exiftool/) it ? – George Profenza Aug 10 '15 at 21:36
  • Yeah that's it. Reading up on this error, turns out there should be a line in the JSON file like so `"SourceFile": "sourcefilename.jpg",` I'm not sure why that wasn't already there. Completely different question but have you any idea of a way I could grab each JSON (or JPG) files' name and put it into each JSON file? I can easily add `"SourceFile": ".jpg",` to every file within seconds, but it's the adding each different name to each different file that would take a long time to do manually. Hope this makes sense... – Raf Aug 10 '15 at 21:49
  • This should be a different question. I haven't played with editing file contents in a look that much. Assuming the json contents are the same, a hacky solution is to simply edit 1 file and pass the same json file to every jpg. It sounds more logical that you would have individual configurations per jpg though. – George Profenza Aug 10 '15 at 23:08
  • No each JSON has seperate tags, descriptions and titles for it's JPG counterpart. I'll make a seperate question. Thank you so very much for all your help! – Raf Aug 11 '15 at 12:38