My first DigiCam was a Canon PowerShot A20 which I bought in 2001. Because of not using Windows but Linux, I had to find solutions to handle everything that has to be done with my DigiCam and Linux. The first problems were, that the most commonly used tool called gphoto was not able to get the photos out of my camera and tricks like 'usb-storage' did not work either. For getting my photos in my PC I found s10sh but it was written for a Canon PowerShot S10 and it hat to be modified in order to support the A20.
Since December 2003, I am a very proud owner of a Canon PowerShot A80 which is (until now) the best camera I can imagine for my purposes (a all-in-one thing, small, smart and with a couple of useful features to play with). s10sh is obsolete because gphoto2 can handle my A80. Manual rotation of pictures is also obsolete (THANK GOD!) because the A80 has a g-sensor and stores the right direction in the EXIF-data section in the jpeg-files. So this page here contents all informations which takes to handle a A20 and a A80 with linux.
During my investigations, I found very useful pages, that content the same and/or similar problems and solutions: Digital photo handling on the command line is a very good howto that lists almost the same solutions as found here (but I found the solutions described here by my own :-) and much more. Geoff's Digicam Tools for Linux has some modifications for some tools (e.g. easy red eye reduction for The Gimp!) and small new tools (e.g. cancomment to add comments) for DigiCam-handling with Linux which you might find useful.
Getting photos from the camera to my harddisk (s10sh, getdigicam)
Canon PowerShot A20
My Digicam (Canon PowerShot A20) has an USB interface to a computer to download the photos from its CompactFlash-card. Because I don't own a card-reader, I am using this USB-cable to get my photos onto my hard disk.
Though my camera model is meanwhile supported by gphoto2, I am using a tool called s10sh. It's kinda old-fashioned but the only thing I need is 'get my photos and save it on my computer' *g*
Because of I am lazy, I wrote a shell-script (see below), that
does all of the important stuff: (called by user root
)
- getting the photos
- lowercase the filenames
- remove unimportant camera-files
- rename the files according to their date and time
- move them to the user-directory
Canon PowerShot A80
s10sh cannot handle my A80 any more and therefore, I use gphoto2 to get the photos:gphoto2 --get-all-files
does the
job very well.
go to top of page
Why not using gphoto2 for a PowerShot A20?
(Obsolete for a newer camera like the A80)
Why not using a tool like gphoto2? I don't need any GUI here. I don't know any GUI which is capable of rotating JPEG photos without losses and I don't want to waste time by clicking instead of getting all work done automatically.
I think gphoto2 also provides a command-line interface but s10sh is much smaller and it does get the job done too :-)
go to top of pageModifying s10sh to support another model like the A20
I had to modify the source of s10sh in order to get it work with my PowerShot A20. Add the lines, where you find it appropriate *g*
,----[ usb.h ] | #define USB_INIT_A20 2 /* A20 found * | #define PRODUCT_ID_A20 0x304e /* PowerShot A20 */ `---- ,----[ usb.c ] | case PRODUCT_ID_A20: | *camera_dev = dev; | if (opt_debug) | printf("Canon A20 found\n"); | return USB_INIT_A20; | break; `----go to top of page
Renaming files
Because many picture manipulating tools modify or delete the EXIF
data stored in the picture files, I prefer to rename every file like
2003-06-01_18h46_img_0084.jpg
where the first part is the
date, when the picture was taken, followed by the time and the
original name.
When I want to add a note to the picture, I rename it (in gqview - as
explained later) like
2003-06-01_18h46_img_0084_Wonderful_Picture.jpg
.
Then I can use every picture manipulating software I need to harm my photos however I want. The filename always stores all the EXIF-data that I want to keep.
As an additional benefit, by using this kind of naming scheme, the files in a directory always keeps the right order.
go to top of pageRotating portrait photos, adding comments (gqview, jpegtran)
My A20 did not have a sensor which does recognize the orientation
of the camera while taking a picture. Therefore, I had to rotate some
of the photos "by hand" in an post-processing step. My current camera,
the A80, saves the orientation in the EXIF-data and I can do
the rotating of all such files automatically by using a tool called jhead (
, the option '-autorot' requires version 2.0 or higher).
The best tool for postprocessing I found yet is called gqview. It's fast and it is capable of calling external tools.
I wrote two bash-scripts, which I placed in ~/bin/
[ turn_jpeg_right.sh ] #!/bin/bash TEMPFILE=turn_jpeg_right_$$_TEMPFILE.jpg [ -f "$1" ] || exit #echo "$1 is a file" /usr/bin/jpegtran -rotate 90 -copy all "$1" >$TEMPFILE && mv $TEMPFILE "$1" #end
[ turn_jpeg_left.sh ] #!/bin/bash TEMPFILE=turn_jpeg_left_$$_TEMPFILE.jpg [ -f "$1" ] || exit #echo "$1 is a file" /usr/bin/jpegtran -rotate 270 -copy all "$1" >$TEMPFILE && mv $TEMPFILE "$1" #end
The scripts requires the tool called jpegtran. It's one of the few tools, that can rotate JPEG-files without the losses of normal tools which are using a very simple (and bad) rotation-algorithm. But be sure that you get at least version 6b in order to use all features in the scripts!
In gqview, I (once) pressed Ctrl-O
(=Edit/Options
) and at Editors
I
wrote at position 5:
"90deg left" "/home/vk/bin/turn_jpeg_left.sh"
and at position 6:
"90deg right" "/home/vk/bin/turn_jpeg_right.sh"
Position 5 and 6, why? As a mnemonic help, I am using the two numbers
above the character t
on my keyboard which stands for 'turn' :-)
So I can go through all my pictures I just downloaded using my shell-script and press
Ctrl-5
(rotate left) or Ctrl-6
(rotate
right) or down
(photo is landscape). This is quite
comfortable and though I used background processing in my scrips
above, it's fast too :-)
When I wish to add a comment to the photos, I rename them and add
(not replace!) some words to them. Every 'event' gets its own
directory like 2003-05-01 Salzburgreise
. Marking and
moving files to new directories is also quite simple using gqview.
For best convenience, I am using screen with a
keyboard binding on Ctrl-a D
(d
for
'digicam') to start gqview in my digicam-download-directory.
So what I have to do is simply:
- (as root) call
getdigicam
(gets all photos to the right directory) - (as user vk) print
Ctrl-a D
(calls gqview) - rotate the pictures (if necessary), add comments, rename them (post-processing)
- mark all photos of one 'event' (archiving)
- right-click &
move
- create a new directory and press
OK
- done.
The script 'getdigicam_a20'
#!/bin/sh
# ------------------------------------------------
# please modify following lines to your values!
# ------------------------------------------------
# download-directory for root:
DLDIR="/root/work/digicam"
# destination-directory for user:
DESTDIR="/home/vk/work/digicam"
# user, group for DESTDIR-user:
DESTUSER="vk"
DESTGRP="users"
JHEAD="/usr/local/bin/jhead"
JHEAD_DATEPAR="-n%Y-%m-%d_%Hh%M_%f"
# path to tool, which lowers all filenames:
LOWERTOOL="/usr/local/bin/lowerall"
# path to s10sh (http://www.kyuzz.org/antirez/s10sh.html)
S10SH="/usr/local/sbin/s10sh"
# parameters for s10sh: (see README from s10sh!)
S10SHPAR="-ug"
# if you have modified all lines according to your
# needs, please alter following value to YES:
USERCONFIG="NO"
#USERCONFIG="YES"
# NOTE: for Canon A20-users: there's a patch for your camera which may
# not be published with s10sh:
# Add the lines, where you find it appropriate *g*
#
# ,----[ usb.h ]
# | #define USB_INIT_A20 2 /* A20 found *
# | #define PRODUCT_ID_A20 0x304e /* PowerShot A20 */
# `----
#
# ,----[ usb.c ]
# | case PRODUCT_ID_A20:
# | *camera_dev = dev;
# | if (opt_debug)
# | printf("Canon A20 found\n");
# | return USB_INIT_A20;
# | break;
# `----
# ------------------------------------------------
# usually you need not modify anything below this line!
# ------------------------------------------------
FILENAME=`echo "$0"|sed 's!.*/!!'`
report()
{
echo "======================================== $FILENAME"
echo " $1"
echo "======================================================"
}
echo
echo " $FILENAME gets all images from a Canon PowerShot digital camera"
echo " and saves them to a directory occupied by root."
echo " Then $FILENAME converts the files to lowercase and moves them"
echo " to a dedicated user-directory."
echo
echo " NOTE: this script needs to be executed by user root!"
echo
echo " USES: s10sh (http://www.kyuzz.org/antirez/s10sh.html)"
echo " lowerall (perl-script, avaliable e.g. at http://llg.cubic.org/tools/)"
echo
echo " AUTHOR: Karl Voit, shellscripts@Karl-Voit.at"
echo " VERSION: v0.2 @ 2003-12-06"
echo " COPYRIGHT: GPL (http://www.gnu.org/copyleft/gpl.html)"
echo
if test "$USERCONFIG" = "NO" ; then
echo
echo "========================================================="
echo " YOU HAVE TO EDIT THIS SCRIPT TO CONFIGURE IT FIRST!!!"
echo "========================================================="
echo " Script aborted."
echo
exit 1
fi
report "switching to $DLDIR and invoking s10sh"
cd ${DLDIR} && ${S10SH} ${S10SHPAR}
#NOTE: "camera_get_last_ls error" is not a problem but unfortunately has
# the same exitcode (1) as other errors, which _are_ a problem, which
# in fact _is_ a problem ;-)
#todo: check, if files were downloaded
report "lowering all filenames of downloaded files"
${LOWERTOOL} "${DLDIR}"/*
report "deleting all qvs- and ctg-files (don't be frightened, you don't need those ;-)"
rm ${DLDIR}/*.ctg ${DLDIR}/100canon.qvs
#todo: only delete them, if there were some (or are there _always_ some?)
#todo: check if valid user/group
report "adding date and time to filenames"
cd ${DLDIR} && ${JHEAD} ${JHEAD_DATEPAR} *.jpg
report "changing all files for user $DESTUSER"
chown ${DESTUSER}:${DESTGRP} ${DLDIR}/*
#todo: check, if valid destdir
report "moving al files to ${DESTDIR}"
mv "${DLDIR}"/* "${DESTDIR}"
#todo: check error-code of mv-stmt
report "end"
#end
go to top of page
The script 'getdigicam_a80'
#!/bin/sh
# ------------------------------------------------
# please modify following lines to your values!
# ------------------------------------------------
# download-directory for root:
DLDIR="/root/work/digicam"
# destination-directory for user:
DESTDIR="/home/vk/work/digicam"
# user, group for DESTDIR-user:
DESTUSER="vk"
DESTGRP="users"
# path to jhead (>= v2.0)
JHEAD="/usr/local/bin/jhead"
JHEAD_DATEPAR="-n%Y-%m-%d_%Hh%M_%f"
# adds a timestamp to a file
DATE_TO_NAME_TOOL="/usr/local/bin/date2name"
# path to tool, which lowers all filenames:
LOWERTOOL="/usr/local/bin/lowerall"
# path to s10sh (http://www.kyuzz.org/antirez/s10sh.html)
DOWNLOADTOOL="/usr/bin/gphoto2"
DOWNLOADTOOLPAR="--get-all-files"
# if you have modified all lines according to your
# needs, please alter following value to YES:
USERCONFIG="NO"
#USERCONFIG="YES"
# ------------------------------------------------
# usually you need not modify anything below this line!
# ------------------------------------------------
FILENAME=`echo "$0"|sed 's!.*/!!'`
report()
{
echo "======================================== $FILENAME"
echo " $1"
echo "======================================================"
}
echo
echo " $FILENAME gets all images from a Canon PowerShot digital camera"
echo " and saves them to a directory occupied by root."
echo " Then $FILENAME converts the files to lowercase and moves them"
echo " to a dedicated user-directory."
echo
echo " NOTE: this script needs to be executed by user root!"
echo
echo " USES: gphoto2"
echo " lowerall (perl-script, avaliable e.g. at http://llg.cubic.org/tools/)"
echo
echo " AUTHOR: Karl Voit, shellscripts@Karl-Voit.at"
echo " VERSION: v0.2 @ 2003-12-06"
echo " COPYRIGHT: GPL (http://www.gnu.org/copyleft/gpl.html)"
echo
if test "$USERCONFIG" = "NO" ; then
echo
echo "========================================================="
echo " YOU HAVE TO EDIT THIS SCRIPT TO CONFIGURE IT FIRST!!!"
echo "========================================================="
echo " Script aborted."
echo
exit 1
fi
report "switching to $DLDIR and invoking download"
cd "${DLDIR}"
"${DOWNLOADTOOL}" "${DOWNLOADTOOLPAR}"
#NOTE: "camera_get_last_ls error" is not a problem but unfortunately has
# the same exitcode (1) as other errors, which _are_ a problem, which
# in fact _is_ a problem ;-)
#todo: check, if files were downloaded
report "lowering all filenames of downloaded files"
${LOWERTOOL} *
report "rotating all images to correct position"
${JHEAD} -autorot *.jpg
report "adding date and time to filenames of images"
${JHEAD} ${JHEAD_DATEPAR} *.jpg
## following line is NOT solved by using jhead any more because of my
## current DigiCam A80 is capable of making avi-movie files which
## don't have EXIF-data. 'date2name' takes the file timestamp (which
## is equal to the timestamp when the photo was taken) and adds it
## to the filename.
report "adding date and time to filenames of movies"
${DATE_TO_NAME_TOOL} *.avi
report "changing all files for user $DESTUSER"
chown ${DESTUSER}:${DESTGRP} ${DLDIR}/*
#todo: check, if valid destdir
report "moving al files to $DESTDIR"
mv "${DLDIR}"/* "${DESTDIR}"
#todo: check error-code of mv-stmt
report "end"
#end
go to top of page