You are not logged in.

#1 2010-09-15 03:22:21

XtrmGmr99
Member
Registered: 2009-04-14
Posts: 128

Renaming photos in KDE4 or terminal using EXIF data

Hello,

I'm trying to batch rename 3,300 photos, and can't figure it out.

I've tried digiKam and KRename, however I can't figure out how to simply rename the files as such:

~/Pictures/[year]/[month]/[datetime].JPG

where the year, month, and datetime are when the picture was taken, via EXIF data. In digiKam, I can't figure out how to rename the files to move to a different dirrectory than their current one, and with KRename, I can't figure out how to only use the year for the directory instead of the entire datetime.

Are there any easy solution for this? It seems really simple...

Offline

#2 2010-09-15 08:10:13

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Renaming photos in KDE4 or terminal using EXIF data

exiftool can do the job.

EDIT: just realised that you want to organise the files into folders. exiftool *can* do that (see the manual and/or web page as there are examples to do just that). But the script below won't.

pacman -S perl-exiftool

This will do all the files in the current folder.

 
for f in *
do
    if [[ ! $f =~ [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]-.*\.[[:alpha:]][[:alpha:]][[:alpha:]] ]]
    then
        exiftool '-filename<CreateDate' -d "%Y-%m-%d-%H%M%S-$f" $f > /dev/null 2>renimg.log
        #dt="$(exiftool -CreateDate $f)"
        #d="$(echo $dt | awk '{print $4 }' | sed 's/:/-/g')"
        #t="$(echo $dt | awk '{print $5 }' | sed 's/://g')"
        #name="$d-$t-$f"
        #echo $f -- $name
        #mv $f $name
    fi
done

It's taken from a script I have. The commented out lines are an alternative way of doing it - slower I think. I used to use another exif extraction tool (exiv2, perhaps?) but lost it and have since forgotten what it was (long story). The commented out lines used to work with that. No idea if that older method was faster or slower, but this does it.

You'll need to change the format and the regex to match your format.
You may to change that it to walk the tree if you have a big structure.

Last edited by skanky (2010-09-15 08:11:34)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#3 2010-09-15 08:12:02

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Renaming photos in KDE4 or terminal using EXIF data

I'd simply use exiftool in a bash script for this:

#!/bin/bash

# copy all jpeg files in and below the current(!) directory to
# ~/Pictures/YEAR/MONTH/DAY/HOUR:MINUTE:SECOND.jpg
#
# requires exiftool (pacman -S perl-exiftool)
#
# USE AT YOUR OWN RISK!

for file in *.jpg **/*.jpg; do
    dest="$HOME/Pictures/$(exiftool -S -d "%Y/%m/%d/%H:%M:%S" -EXIF:DateTimeOriginal $file | awk '{print $2}').jpg"
    
    echo "$file -> $dest"
    # install -v -D -m 644 "$file" "$dest" && rm "$file"
    # ^ uncomment the above line if you're sure this is what you want
done

The above script has a "safety lock", i.e. it will only print what it will do until you uncomment the "install" line.

Note that if more than one picture was taken in the same second, the first pictures will be overwritten since the filenames will be equal.

Hope this helps...

Offline

#4 2010-09-15 20:58:01

XtrmGmr99
Member
Registered: 2009-04-14
Posts: 128

Re: Renaming photos in KDE4 or terminal using EXIF data

Thanks so much you guys.

I take it there is no easy way to do this in a GUI fashion? I don't mind using a script, but I'm not very versed in bash scripting and changing things around is a matter of trial and error for me.

I wonder if I can create a PHP script for this... I'm more more knowledgable with PHP, though I've never used it outside of web applications...

Offline

Board footer

Powered by FluxBB