#!/bin/bash # # Copies and renames images by stripping the _dpi suffix # Usage rename-strip-dpi.sh [-resize arg] {destdir} files PROG="cp" if [ "$1" = "-resize" ]; then shift PROG="convert -resize $1" shift fi SUFFIX="" if [ "$1" = "-suffize" ]; then shift SUFFIX=$1 shift fi DEST="$1" shift SRC=$@ if [ ! -d "${DEST}" ]; then echo "Destination: ${DEST} does not exist" exit 1 fi function doit(){ extn=$1 for f in ${SRC}; do name=`basename $f ${extn}` if [ $name = `basename $f` ]; then echo "Skip: $name${extn}" continue fi name=`echo $name | sed -E 's/_([0-9]+|NA)$//'`${SUFFIX}${extn} destfile="${DEST}/$name" echo "$PROG $f to $destfile" $PROG "${f}" "${destfile}" done } doit .png doit .jpg exit 0