Mailinglist Archive: opensuse (1420 mails)

< Previous Next >
[opensuse] gphoto2 - download image file rename/classify helper script
All,

Using gphoto2 to download, delete or upload images to apple devices is really
handy, but the default filenames contained on the device are horrible.
(non-descript, upper-case, etc..). For example, after downloading all images
from your device you have a directory full of:

02:44 alchemy:~/mmedia/iPhone/iph3-black-sav> l1
IMG_0001.JPG
IMG_0002.JPG
IMG_0016.MOV
IMG_0032.PNG
IMG_0033.JPG
IMG_0034.PNG
IMG_0182.MOV
IMG_0183.JPG
IMG_0186.MOV
IMG_0188.MOV
IMG_0189.JPG
IMG_0190.JPG
...

This contains all images in the "camera roll" including photos, saved graphic
files and videos. For permanent storage, I want the photos separated from the
graphic and video files in a way that is easy to manage. If anyone has a similar
issue, I've cobbled together a helper script to parse the file, examine the EXIF
and PNG headers and rename them into separate directories with filenames that
contain the image (or filemod) date along with the original image number for
reference. Example:


bkgnd
img_20120102-195924_0024.jpg
img_20120102-203607_0034.png
images
img_20120102-203551_0032.png
img_20120102-203559_0033.jpg
photos
iPhone_3GS_20130509-154717_0470.jpg
iPhone_3GS_20130707-142745_0517.jpg
videos
img_20111226-133705_0016.mov
img_20120303-173828_0177.mov


The help file for the script is fairly self-explanatory. The script takes
either a single filename or directory as its only input and the
{bkgnd,images,photos,videos} subdirs are created under the given file or
directory path. The find statement used when a directory is passed to the script
is limited to -maxdepth 1 so it only operates on a single directory. The help
is:

02:53 alchemy:~/mmedia/iPhone> ~/scr/photo/iphrename.sh -h

Usage: iphrename.sh /path/to/iPhone/image/download

iphrename.sh reads a directory containing image filenames in the form
IMG_####.EXT (as downloaded by gphoto2 from an iPhone) and performs an
intelligent rename of the files and moves the files into the following
subdirectories:

bkgnd : background images, named img_YYYYMMDD-HHMMSS_####.ext
(criteria: jpg/png horiz. image resolution <= 500)

images : non-photo images, named img_YYYYMMDD-HHMMSS_####.ext
(criteria: jpg/png horiz. image resolution > 500 &&
no EXIF camera model)

photos : photo images, named <EXIF-model>_YYYYMMDD-HHMMSS_####.ext
(criteria: jpg horiz. image resolution > 500 &&
EXIF camera model)

videos : video images, named img_YYYYMMDD-HHMMSS_####.ext
(criteria: .MOV extension)

All filenames are translated to lowercase. '####' in the filename preserves
the image number from the original filename (IMG_####.EXT) allowing complete
reversal of the file rename. For photos, the YYYYMMDD-HHMMSS is the original
camera image data generation date/time (if available), otherwise for jpeg
images it is file creation date/time contained within the EXIF data. For PNG
and MOV files, the YYYYMMDD-HHMMSS date/time is the file modification time
as returned by 'stat -c%y'.

Options:

-h | --help program help (this file)

If you are interested in the script, you can grab copy here:

http://www.3111skyline.com/dl/linux/scripts/photo/iphrename.sh.txt

I added a .txt extension so you could browse it on the web-server. It has
reasonable comments, and as always use it, cannibalize it, whatever. If you,
heaven forbid, find a screw-up in it, or (DH) see something that could be done
better, just let me know. Thanks.

--
David C. Rankin, J.D.,P.E.
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >