Скрипти – Scripts

The placeWatermark script

#!/bin/bash

############################################################################################################################################
# File: placeWatermark.sh                                                                                                                  #
# Release: v0.1                                                                                                                            #
# Purpose: This script scans photos in a given directory, changes its extensions to lower cases and places watermarks (copyright) on them. #
# Warning: It is recommended to copy photos from a source directory to a test one that is why the script asks for a test directory.        #
#           This is just for back-up purposes.                                                                                             #
# Dependencies: sudo apt-get install imagemagick exiv2											   #
# Author: Maksym Stetsyuk														   #
# Copyright: (C) 2011        														   #
# Comments: This file is distributed without warranty and you are free to make any modifications in the source code                        #
#           (as long as those modifications will not break the script). 						                   #
# Contact: Any feedback is welcome to my e-mail address: maxsteciuk <AT> gmail.com 							   #
############################################################################################################################################

EXT="*.jpg"

if [ $# -lt 3 ]
then
  echo "Not enough arguments"
  echo "Usage: " $0 " <work directory> <test directory> <signature image>"
  exit 1
fi

WORK_DIR=$1
TEST_DIR=$2
SIGN_PATH=$3

if [ ! -d $TEST_DIR ]
then
  mkdir $TEST_DIR
fi

echo $WORK_DIR

echo "Renaming... "
for i in $( ls $WORK_DIR )
do
  case $i in
  *.JPG)
     echo "+++ if .JPG... $i"
     rename 's/\.JPG$/.jpg/' $WORK_DIR/$i
     ;;
  * )
     echo "+++ extension is fine... $i"
     ;;
  esac
done

echo "Copying..."
for i in $( ls $WORK_DIR )
do
   cp -v $WORK_DIR/$i -t $TEST_DIR/
done

echo "Going to the test directory..."
cd $TEST_DIR

echo "Processing images..."
for i in $EXT
do
 echo "+++ file $i: `exiv2 -g Exif.Image.Orientation -pv $i | awk '{print $6;}'`" # get the field of the orientation tag that is responsible for whether it is horizontal or vertical
 case `exiv2 -g Exif.Image.Orientation -pv $i | awk '{print $6;}'` in
 # 1 - for horizontal; 6 - for vertical
 1)
    RATIO=20
    tmpWdth=`exiv2 -g Exif.Photo.PixelXDimension  $i   | awk '{print $4;}'`
    perfectWdth=`expr \( $RATIO \* $tmpWdth \) \/ 100` # calculating perfect width for the watermark

    echo "the image is horizontal!"
    composite  -gravity SouthEast  -geometry $perfectWdth"x320+50+50"  $SIGN_PATH $i $i
    ;;
 6)
    echo "the image is vertical!"
    composite  -gravity northWest -geometry 420x220+50+50  $SIGN_PATH $i $i
    ;;
  *)
    echo "orientation unknown!"
    ;;
  esac

done

echo "Processing is done!"

The resizePhotos script

#!/bin/bash

############################################################################################################################################
# File: resizePhotos.sh                                                                                                                    #
# Release: v0.1                                                                                                                            #
# Purpose: This script is for resizing photos which were watermarked and that are to be exported to the Web.                               #
# Dependencies: sudo apt-get install imagemagick exiv2											   #
# Author: Maksym Stetsyuk														   #
# Copyright: (C) 2011        														   #
# Comments: This file is distributed without warranty and you are free to make any modifications in the source code                        #
#           (as long as those modifications will not break the script :)  ). 						                   #
# Contact: Any feedback is welcome to my e-mail address: maxsteciuk <AT> gmail.com 							   #
############################################################################################################################################

EXT="*.jpg"

TEST_DIR=$1
desiredWidth=$2 # given via command-line argument

if [ $# -lt 2 ]
then
   echo "Not enough arguments "
   echo "Usage: " $0 "<test directory> <desired width>"
   exit 1
fi

if [ ! -d $TEST_DIR ]
then
  echo "No such directory."
fi

cd $TEST_DIR

for i in $EXT
do

     tmpWdth=`exiv2 -g Exif.Photo.PixelXDimension  $i   | awk '{print $4;}'` # getting the width of the photo
     ratio=$(echo "$tmpWdth/$desiredWidth*100" | bc -l)                     # computing the ratio of resizing
     ratio=$(echo $ratio | sed 's/\.[0-9]*$//')                             # trunkating to int

    # just a sanity check
    if [ $ratio == 0 ]
    then
          echo "CAUTION! Division by zero!"
          exit 1
    fi

   #this is for debugging

   # echo "tmpWidth: " $tmpWdth "----" $i
   # echo "ratio:  " $ratio
   # echo "+++ratio expr \( $tmpWdth \/ $desiredWidth \) \* 100"   

    tmpLgth=`exiv2 -g Exif.Photo.PixelYDimension  $i   | awk '{print $4;}'` # getting the length of the phot
    desiredLength=`expr \( $tmpLgth \/ $ratio \) \* 100`                    # desired length of the photo with respect to a computed ratio

   # this is for debugging
   # echo "+++ length expr \( $tmpLgth \/ $ratio \) \* 100"   

    echo "Resizing the photo: <$i>"
    convert -resize $desiredWidth"x"$desiredLength $i $i    

done

echo "Processing is done!"
  1. Ще немає коментарів.
  1. Немає ще трекбеків.