日期戳照片

日期戳照片

我的电脑上有许多照片,图片底角没有数据戳。

是否有一个程序可以帮助我为这些照片添加日期戳?

我有 ubuntu 16.04

答案1

如果你能安装具有良好 GUI 的“phatch”,我强烈推荐这个。但是,即使安装了建议的补丁,我还是无法在我的 ubuntu 16.04 上安装它。

因此,我开始寻找它的替代品。“ImageMagick”是我现在使用的。它在命令行(CLI)下运行,并编写了一个脚本文件来简化任务。下面是我写的脚本文件。看一看,它可能会对你有所帮助。修改它以满足您的需要。充分测试它,您可以将您的版本脚本文件复制到 /usr/local/sbin 目录中以方便访问。

#!/bin/bash
# set destination directory
d_dir=im
# copy the destination directories structure only
# input source directory
s_dir=""
flag=0
until [ $flag == "1" ] ; do
  clear
  printf "\n"
  ls -d */
  printf  "\nEnter the name of one of the folders above to processed. \n\n"
  read s_dir  # input source directory
  ls -d */ | grep -wq $s_dir && flag=1 || echo printf "\nDirectory not exist!" ; sleep 2
done

printf  "\nCreating destination folder(s):  ./$d_dir/$s_dir\n"
rsync -avq -f"+ */" -f"- *" ./$s_dir ./$d_dir

#
# Overwrite the existing file(s)?
#

printf  "\nOverwrite existing file(s)?\n"
printf  "\nPress [Y/y] or [N/n] ... "
tput sc  # save the cursor current position

overwrite=""
until [ "$overwrite" = "y" -o "$overwrite" = "n" ] ; do
  read -s -n 1 overwrite  # printf n "\033[K"  erase to end of the line
  tput rc ; tput cub 1 ; tput el ; tput cuf 1  # restore cursor position, move 1 left, erase to end of the line , move 1 right
  printf  "$overwrite\b"        # \b --backspace
  overwrite=$(echo $overwrite | tr 'A-Z' 'a-z')  # translate to lower case
done
printf "\n\n"

#
# list file names in associated path
# find source_dir -type f -name \*.[Jj][Pp][Gg]
#

for img in $(find $s_dir -type f -name \*.[Jj][Pp][Gg] 2> /dev/null ) 
 do 
  if ! [ -f $d_dir/"$img" -a $overwrite = "n" ] ; then

# write and overwrite image file with date stamp 
# read exif meta-data from the image file

read ymd hms orient wid leng \
    <<< $(identify -format '%[exif:DateTimeOriginal]  \
    %[exif:Orientation] %[exif:ExifImageWidth] \
    %[exif:ExifImageLength]\n' $img)

year=${ymd:0:4}; mon=${ymd:5:2}; day=${ymd:8:2}
hour=${hms:0:2}; min=${hms:3:2}; sec=${hms:6:2}


# calculate the pointsize --- 3.5% of the smaller one --- width or length

if [ "$wid" -gt "$leng" ] ; then
    let ptsz=$leng*35/1000    # 35/1000 is from try and error
else
    let ptsz=$wid*35/1000
fi

#
# rotate image first according to the orientation
# rotate back(reverse) after process
#
# TopLeft - 1, BottomRight - 3, RightTop - 6, LeftBottom - 8
#    1
#  6   8    
#    3
#

case $orient in
  "1")
    rotate_1st="" 
    rotate_reverse=""
    let tx=$wid/100      # 100 is from try and error
    let ty=$leng/120     # 120 is from try and error

  ;;
  "8")
    rotate_1st='-rotate -90' 
    rotate_reverse='-rotate +90'
    let tx=50
    let ty=50
  ;;
  "3")
    # actually, I do not have photo with orientation 3, 
    # the tx and ty are just wild guess.
    rotate_1st='-rotate -180' 
    rotate_reverse='-rotate +180'
    let tx=$wid/100  
    let ty=$leng/120 
  ;;
  "6")
    # actually, I do not have photo with orientation 6, 
    # the tx and ty are just wild guess.
    rotate_1st='-rotate +90' 
    rotate_reverse='-rotate -90'
    let tx=50
    let ty=50
  ;;
esac

 convert "$img" \
    $rotate_1st \
    -gravity SouthEast \  # date stamp at bottom right of photo
    -pointsize $ptsz \
    -fill red \
    -font Ubuntu-Mono \
    -annotate +"$tx"+"$ty" "@ $hour:$min:$sec\n$year-$mon-$day" \
    $rotate_reverse \
    $d_dir/"$img" 

   printf "$d_dir/$img  converted.\n"
 fi
done
printf "Done! \n"

相关内容