How to manage photos with Linux easily.

in #linux3 years ago

I'm using linux on my personal desktop since a long time and as a lot of people, I have a camera to take picture during holidays, with family, nature photography, etc..
My camera is a Panasonic Lumix FZ200 and my favorite Linux distribution is Linuxmint.

thumb_cinnamon.png

The tool to manage and look my photos is shotwell : https://wiki.gnome.org/Apps/Shotwell
This tool can sort your photos by year/month/day automatically, but what I like is also to have directories sorted with all my photos to retrieve them easily later by block. For example, to create a compressed file of some photos of a specific day, or just to show on a usb drive somme photos.

this look like below when all my photos are sorted automatically :

Sélection_066.png

But the main important thing is the transfer from the camera to the PC. If you have a lot of images/videos with different format (Raw, Jpg, mp4) but you want to keep on your camera SD card, it could be a huge work to grab only your last ones manually.

So, I decided to write a simple linux script that will do the following steps :

  • Get only the last pictures on my camera
  • Filter the files format (jpg, raw,mts, mp4, etc...)
  • Convert the files names with date timestamp

We first need to install some image software to grab exif information : exiv2
On ubuntu/debian dsitribution, let enter : sudo apt install exiv2

This done, the first thing to know is the mount point of the camera when you connect it to the PC.
After connecting camera, you will see the directory available in the file manager :

Sélection_067.png

By cliking on it, the mount point will be displayed :

Sélection_068.png

Here you can see it is : /media/david/6535-3833 , let's keep this mountpoint in mind.

Now the script, the main part are commented and this script is very simple, but helps a lot !

#!/bin/bash

# ----------------------------------------------------------------
# output directories for each file format
# ----------------------------------------------------------------
JPEGDIR=/data2/david/photos/JPEG/
RAWDIR=/data2/david/photos/RAW/
RSYNCDIR=/data2/david/photos/RSYNC/
# ----------------------------------------------------------------
 # Mount point for the camera
# ----------------------------------------------------------------
DIRLUMIX=/run/media/david/6535-3833
# ----------------------------------------------------------------
# Specific directories (but not use on my Lumix camera)
# ----------------------------------------------------------------
MTSDIR=$DIRLUMIX/PRIVATE/AVCHD/BDMV/STREAM
# ----------------------------------------------------------------
# Check if mount point exists
# ----------------------------------------------------------------
if [ -d $DIRLUMIX ];then
       # the --ignore-existing donc download the file from the camera to the pc if present
    rsync -av --ignore-existing $DIRLUMIX/DCIM/*_PANA/*.RW2 /data2/david/photos/RAW/
    rsync -av --ignore-existing $DIRLUMIX/DCIM/*_PANA/*.JPG $RSYNCDIR
    rsync -av --ignore-existing $DIRLUMIX/DCIM/*_PANA/*.MP4 /data2/david/photos/MP4/
    rsync -av --ignore-existing $MTSDIR/*.MTS /data2/david/photos/MTS/
fi
cd $RSYNCDIR
rename 's/\.jpg$/\.JPG/' *
#jhead -n%Y-%m-%d-%H-%M-%S *.jpg

# ----------------------------------------------------------------
# Process first the RAW image files
# ----------------------------------------------------------------
cd $RAWDIR
for file in `ls *.RW2`;do
   if [ ! -L $file ];then
       # Depending on your language settings : French
       date=$(exiv2 "$file" 2> /dev/null | awk '/Horodatage/ { print $4 }')
       # English : 
        date=$(exiv2 "$file" 2> /dev/null | awk '/Image timestamp/ { print $4 }')
       [ -z "$date" ] && echo "$file" >> ~/error.txt && continue
       year=${date%%:*}
       month=${date%:*}
       month=${month#*:}
       day=${date##*:}
       outdir="$RAWDIR/${year}/${month}/${day}"
       mkdir -p $outdir
           # Move the image file to the timesamped directory
       mv $file $outdir/$file
       # Create a symobolic link, this is important as this will disable the copy of existing file
           # with the rsync command, this will save a lot of time.
       ln -s $outdir/$file $file
    fi
done
# ----------------------------------------------------------------
# Process the JPEG files
# ----------------------------------------------------------------
cd $RSYNCDIR
for file in `ls *.JPG`;do
    if [ ! -L $file ];then
           # Depending on your language settings : French
       # Horodatage in French, timestamp in english
       date=$(exiv2 "$file" 2> /dev/null | awk '/Horodatage/ { print $4 }')
           heure=$(exiv2 "$file" 2> /dev/null | awk '/Horodatage/ { print $5 }')
           newheure=$(echo $heure|sed -e "s/:/-/g")
       #date=$(exiv2 "$file" 2> /dev/null | awk '/Image timestamp/ { print $4 }')
       [ -z "$date" ] && echo "$file" >> ~/error.txt && continue
       year=${date%%:*}
       month=${date%:*}
       month=${month#*:}
       day=${date##*:}
       outdir="$JPEGDIR/${year}/${month}/${day}"
       mkdir -p $outdir
       newfile="${year}-${month}-${day}-${newheure}"
       mv $file $outdir/${newfile}.jpg
       ln -s $outdir/${newfile}.jpg $file
    fi;
done

now , so create a file (lumix.sh for example) with this above content and set the file as executable :

chmod u+x lumix.sh

To access this file, you can create a shortcut on your desktop to access it easily.

So with that, now what I do is :

  • I take some pictures with my camera
  • I connect it to my PC
  • I run the script and the last photos are available in their own directories arranged by date.

And th'as all , simple not ?


And you how do you manage your photos ? Do you use specific tools ?