修改照片文件名为EXIF日期时间的脚本

上一篇 / 下一篇  2008-05-26 00:07:21 / 个人分类:Shell

查看( 624 ) / 评论( 0 )
#!/bin/bash
#
# wmdd - Weapon of Mass Duplicate Detection
#
# I wrote this because I was having a hard time identifying duplicate
# images in my f-spot Photos folder. I decided I should just rename all
# of the pictures based on the EXIF data to YYYY-MM-DD-HH-mm-SS.jpg format.
# If pictures have identical EXIF data, then '_copy' is added to the file
# name. Operation is recursive.
#
# To make it a little easier, I have the scrīpt copy pictures to a folder,
# 'exif/YYYY' or 'noexif' depending on whether there is EXIF info or not.
# This also make reimporting to f-spot a little easier.
#
# Requires exif package.
#
# To run, cd to the top-level directory of the images you want to rename.
#
# Todd Slater
# 14 May 2007

original_pic_dir=`pwd` # maybe at some point make this an optional argument
cp_dir="$original_pic_dir/exif"
noexif_dir="$original_pic_dir/noexif"
# find images
find $original_pic_dir -type f -iname '*.jpg' >> piclist
while read line
do
# test for exif
if [ -z `exif -t DateTimeOriginal "$line"` >/dev/null 2>&1 ] ; then
# no exif, let's copy it to noexif_dir, but not overwrite existing files
pic_name=`echo "$line" |sed s/" "/_/g | xargs basename`
while [ -f "$noexif_dir/$pic_name" ] ;
do
pic_name=`echo "$pic_name" | sed s/\.jpg/_copy\.jpg/`
done
if [ ! -d $noexif_dir ] ; then
mkdir -p $noexif_dir
fi
cp "$line" "$noexif_dir/$pic_name"
else
# has exif, let's rename and copy to exif/YYYY folder
exif -t DateTimeOriginal "$line" |grep Value > exif.$$
year=`cut -b 10-13 "exif.$$"`
month=`cut -b 15-16 "exif.$$"`
day=`cut -b 18-19 "exif.$$"`
hour=`cut -b 21-22 "exif.$$"`
minute=`cut -b 24-25 "exif.$$"`
second=`cut -b 27-28 "exif.$$"`
rm exif.$$
exif_name="$year-$month-$day-$hour-$minute-$second.jpg"
while [ -f "$cp_dir/$year/$exif_name" ] ;
do
exif_name=`echo $exif_name | sed s/\.jpg/_copy\.jpg/`
done
if [ ! -d "$cp_dir/$year" ] ; then
mkdir -p "$cp_dir/$year"
fi
cp "$line" "$cp_dir/$year/$exif_name"
fi
done < piclist
rm -f piclist

TAG: Shell

我来说两句

(可选)

日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 937
  • 日志数: 11
  • 图片数: 2
  • 建立时间: 2006-01-10
  • 更新时间: 2008-08-14

RSS订阅

Open Toolbar