Rooot.net

  • Increase font size
  • Default font size
  • Decrease font size
Living in a wooden world.
Home Geek stuff Linux Resize, rotate and rename your holiday photos

Resize, rotate and rename your holiday photos

Yay, it's holiday time! playa, mountain, road trip... Everyone had a camera and everyone took so much pictures... and there are now hundreds of photos from several devices to resize, rotate and rename Surprised !

To make this an easier task, here are some tools to the rescue Wink. Remember to backup your pictures before performing any change to prevent errors or data loss.

Resize and rotate pictures

To upload some photos on the web or to save some space, you may want to resize and rotate your pictures. Image rotation is usually stored in exif metadata, but there is still a lot of software that can't read these information (WinXP built-in slideshow, some poorly coded web galleries, ...).

First install some tools to transform your images.

~$ aptitude install imagemagick exiftran

Then get the resizePictures.sh script and change the following parameters to your needs:

  • PICT_EXT: picture extension (case sensitive)
  • MAX_PICT_WIDTH: the picture maximal width (or height for portrait orientation)
  • PICT_QUALITY: quality (jpeg compression parameter)

#!/bin/bash
# resizePictures.sh
# By neo73 [at] rooot [dot] net - Last modified march 2010
# Resize big pictures in a folder.
# This script requires convert and identify (from ImageMagick) and exiftran.
# USE AT YOUR OWN RISK

PICT_EXT=jpg
MAX_PICT_WIDTH=2592
PICT_QUALITY=85

function usage {
echo "Usage: $0 <folder>"
exit
}

if [ ! $# -eq 1 ]; then
usage
fi

dir=$1
if [ ! -d "$dir" ]; then
echo "Error: \"$dir\" is not a folder"
exit 0
fi

cd "$dir"
IFS_BAK=$IFS
export IFS='
'
for file in `ls *.$PICT_EXT`; do
args=""

echo -n '.'

# First fix orientation
orientation=$(identify -format "%[EXIF:Orientation]" "$file")
if [ "$orientation" != "1" ]; then
# convert won't update exif info so we use exiftran.
exiftran -a -i "$file"
fi

#Then resize image
convert -resize "$MAX_PICT_WIDTH>x$MAX_PICT_WIDTH>" -quality "$PICT_QUALITY" "$file" "$file"
done
echo

export IFS=$IFS_BAK

Rename pictures

Camera makers have their own file naming convention. When you are using several cameras that makes impossible to browse the pictures in a chronological order. The best way to achieve it is to rename your picture using their creation date.

We need another tool to read image creation date from exif metadata.

~$ aptitude install libimage-exiftool-perl

Next step is to check the image creation date is correct. You may have a time shift between two different cameras or maybe you forgot to setup date / time on your device before shooting pictures.

The renamePictures.sh script will take care of date ajustment and file renaming. Keep pictures from different cameras in separate folders and run the script on each folder. Just give a reference date and reference file as script parameters and it will shift all picture's date.

#!/bin/bash
# renamePictures.sh
# By neo73 [at] rooot [dot] net - Last modified july 2010
# Rename pictures in a folder.
# This script requires libimage-exiftool-perl.
# USE AT YOUR OWN RISK

PICT_EXT=jpg
adjustTs=0
adjustSign='+'
function usage {
echo "Usage: $0 [-d <YYYY-MM-DD hh:mm:ss> <reference_file>] <folder>"
exit
}

if [ $# -lt 1 ]; then
usage
fi
if [ $# -gt 1 ]; then
if [ "$1" != "-d" ]; then
usage
fi
if [ ! $# -eq 4 ]; then
usage
fi

referenceDate=$2
referenceFile=$3
if [ ! -f "$referenceFile" ]; then
echo "Error: \"$referenceFile\" is not a file"
fi
dir=$4

referenceTs=`date -d "$referenceDate" +%s`

myDate=`exiftool -TAG -CreateDate "$referenceFile" -d "%Y-%m-%d %H:%M:%S" -s -s -s`
myTs=`date -d "$myDate" +%s`

adjustTs=$(($referenceTs - $myTs))
if [ $adjustTs -lt 0 ]; then
adjustSign='-'
adjustTs=$((-$adjustTs))
fi
else
dir=$1
fi

if [ ! -d "$dir" ]; then
echo "Error: \"$dir\" is not a folder"
exit 0
fi

cd "$dir"


# fix picture dates
exiftool -AllDates${adjustSign}="::$adjustTs" -overwrite_original .

# rename pictures
exiftool '-FileName<${CreateDate}.jpg' -d %Y%m%d_%H%M%S *.$PICT_EXT

Now that your pictures are renamed, you can move all of them in the same folder and do whatever you want with them Laughing.

Comments
Add New Search
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."