Hi all. I'm new to exiftool but overwhelmed by the possibilities. Now I tried to manage a specific and tricky task but failed - maybe one of you can help me here:
I want to rename a bunch of photos in a directory (showing my daughter) depending on her age, i.e., depending on the difference between the date the picture was taken (read from EXIF data) and a given (on the command line) birthday date to compare to. Since I have, well, thousands of pictures of my children, this would be enormously helpful.
Ideally, the date difference should follow a format I use: aYbMcD_%%f.%%e, where a is the difference in full years, b the remaining full months and c the days, all with leading zeroes.
An example: A photo shot on, say, April 15th, 2016 and a given birthday date of May 2nd, 2010 would then be renamed to 05Y11M13D_<original filename> - and I could see from the file name that my daughter was 5 years, 11 months, and 13 days old when the picture was taken.
Is this possible with exiftool?
Thank you for your help,
Gainor
Previous (long) thread (https://exiftool.org/forum/index.php/topic,5708.0.html) with a similar goal.
Hi Gainor,
That long thread that StarGeek mentioned was similar, but it is actually very tricky calculating the days because they change for each month. Attached is a config file that does this. For this you enter the birthday with the -userparam option, so the command would look like this:
exiftool -config age.config "-filename<${age}_%f.%e" -userparam birthday="2010:05:02" DIR
- Phil
Whoa, this is great, thank you! :) Your script does all the magic!
I didn't see the old thread with a similar (and even in parts more complex) intention and now I'm delving into it in order to find out what other things exiftool can do. This is a really powerful tool. You rock! ;)
I use -if conditions to print the age of persons NAME1, NAME2 and/or NAME3, but between the lines Exiftool gives this warning/informational message: "Ignored -config option (not first on command line)". I tried to suppress the warning/informational messages with the -q -q options, but it didn't work. How can I print the three lines without the warnings/informational messages?
MacBook-Air-van-Fulco:~ Fulco$ exiftool -config age.config -if '$Subject=~/NAME1/' -q -q -p 'NAME1: $age' -userparam birthday="2007:12:23" -execute -config age.config -if '$Subject=~/NAME2/' -q -q -p 'NAME2: $age' -userparam birthday="2009:04:13" -execute -config age.config -if '$Subject=~/NAME3/' -q -q -p 'NAME3: $age' -userparam birthday="2010:07:12" -common_args /Users/Fulco/Pictures/Test/20140918175032.jpg
NAME1: 06 Years, 08 Month(s) and 26 Day(s)
Ignored -config option (not first on command line)
NAME2: 05 Years, 05 Month(s) and 05 Day(s)
Ignored -config option (not first on command line)
NAME3: 04 Years, 02 Month(s) and 06 Day(s)
- Fulco
Hi Fulco,
The -config option shouldn't be repeated after each -execute
I will make this clear in the documentation.
- Phil
Yes! It works. Thanks!
MacBook-Air-van-Fulco:~ Fulco$ exiftool -config age.config -if '$Subject=~/NAME1/' -q -q -p 'NAME1: $age' -userparam birthday="2007:12:23" -execute -if '$Subject=~/NAME2/' -q -q -p 'NAME2: $age' -userparam birthday="2009:04:13" -execute age.config -if '$Subject=~/NAME3/' -q -q -p 'NAME3: $age' -userparam birthday="2010:07:12" -common_args /Users/Fulco/Pictures/Test/20140918175032.jpg
NAME1: 06 Years, 08 Month(s) and 26 Day(s)
NAME2: 05 Years, 05 Month(s) and 05 Day(s)
NAME3: 04 Years, 02 Month(s) and 06 Day(s)
I've been playing around with this a bit more, and have worked up a more general config file that may be more widely useful. I'm thinking of including this in the next ExifTool release. See the comments in the file for documentation and examples.
@Gainor: This new config file should work for you with the following command:
exiftool -config age.config "-filename<${age}_%f.%e" -userparam birthday="2010Y05M02D" DIR
(ie. change the specified Birthday to use the same format as you want for the Age.)
- Phil
Thank you very much, this works like a charm. I'm happy that you want to add this to the next exiftool release, making this solution available to many more users. :)
One more idea: Could you add some functionality that checks whether the file already has a date string like this, i.e., whether the (identical) date string to be added is already there? Currently, if I use it in the same directory twice, I have to re-rename the files by hand and delete the duplicate date string. This might be interesting if new files are added to a directory and already treated pictures can then easily be skipped by the script, renaming only the newcomers.
You do this to avoid adding Age twice to the filename:
exiftool -config age.config "-filename<${age}_%f.%e" -userparam birthday="2010Y05M02D" -if "$filename !~ /$age/" DIR
- Phil
Very cool if you include this feature into the next relaease! Is it also possible to calculate how many years, months, days, hours and minutes ago the picture was taken, i.e. the time span between the DateTimeOriginal and the current time ("now")?
- Fulco
PS, I'm not sure where to post this feature request.
Hi Fulco,
Interesting. I'll think about this.
- Phil
You can sorta do it with the same config, just input the current day. The one problem is that it comes out negative. Fixable if copying a tag with ${age;s/^-//}
Calculating the negative time difference turns out to be more complicated than just removing the "-" sign. Each of the components must be negated because they were subtracted in the wrong order. Also, the number of days in the start month must change to the month in which the photo was taken instead of the birthday month.
Attached is an updated config file that handles negative time differences properly.
- Phil
Thank you Phil! I used your new config file to print the age of person and age of the image file itself.
MacBook-Air-van-Fulco:~ Fulco$ exiftool -config /Users/Fulco/Downloads/age.config -q -q -p 'Age of photo : $Age' -userparam birthday= -execute -q -q -p 'Age person on photo: $Age' -userparam birthday="2000:07:02 18:28" -age -common_args /Users/Fulco/Pictures/Test/20160702_182802.jpg
Age of photo : 00:06:22 21:40:00
Age person on photo: 16:00:00 00:00
If I don't use the -q -q options in the command, Exiftool gives warning messages (see below). Is it something to worry about?
MacBook-Air-van-Fulco:~ Fulco$ exiftool -config /Users/Fulco/Downloads/age.config -p 'Age of photo : $Age' -userparam birthday= -execute -p 'Age person on photo: $Age' -userparam birthday="2000:07:02 18:28" -age -common_args /Users/Fulco/Pictures/Test/20160702_182802.jpg
Age of photo : 00:06:22 21:41:15
Warning: ValueConv Age: Use of uninitialized value within @diff in numeric lt (<) - /Users/Fulco/Pictures/Test/20160702_182802.jpg
Age person on photo: 16:00:00 00:00
Warning: ValueConv Age: Use of uninitialized value within @diff in numeric lt (<) - /Users/Fulco/Pictures/Test/20160702_182802.jpg/
- Fulco
Hi Fulco,
Thanks. I have patched the config file to hopefully fix this problem. Attached is the new version.
But you should be getting brackets around the returned value if the birthday is not specified or comes after the photo date/time. (also, you can drop the "-userparam birthday=" from your command if no birthday is given)
- Phil
Hello Phil,
Without the -q -q options I don't get the warning messages anymore ;D I removed the brackets from the config file myself. Does it effect the calculation? If so, I will restore them.
MacBook-Air-van-Fulco:~ Fulco$ exiftool -config /Users/Fulco/Downloads/age.config -p 'Age of photo : $Age' -execute -p 'Age person on photo: $Age' -userparam birthday="2000:07:02 18:28" -age -common_args /Users/Fulco/Pictures/Test/20160702_182802.jpg
Age of photo : 00:06:23 03:21:16
Age person on photo: 16:00:00 00:00
Thanks again!
- Fulco
Nope, the brackets don't affect anything. I was just wondering if it was working properly. Sounds like it is.
- Phil