"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/rot-jpg.in" between
littleutils-1.2.3.tar.lz and littleutils-1.2.4.tar.lz

About: littleutils are a collection of small and simple utilities (rename files, search for duplicate files, ...).

rot-jpg.in  (littleutils-1.2.3.tar.lz):rot-jpg.in  (littleutils-1.2.4.tar.lz)
#! PROGDASH #! PROGBASH
# vim: set filetype=sh: # vim: set filetype=bash:
# rot-jpg: Losslessly rotate JPEG files # rot-jpg: Losslessly rotate JPEG files
# Copyright (C) 2019 by Brian Lindholm. This file is part of the littleutils # Copyright (C) 2019-2021 by Brian Lindholm. This file is part of the
# utility set. # littleutils utility set.
# #
# The rot-jpg utility is free software; you can redistribute it and/or modify # The rot-jpg utility is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the Free # it under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later version. # Software Foundation; either version 3, or (at your option) any later version.
# #
# The rot-jpg utility is distributed in the hope that it will be useful, but # The rot-jpg utility is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. # more details.
# #
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# the littleutils. If not, see <https://www.gnu.org/licenses/>. # the littleutils. If not, see <https://www.gnu.org/licenses/>.
# get a valid temporary directory and set up traps
TMPWILD=`tempname -w rot-jpg_$$` || exit 99
trap 'rm -f ${TMPWILD} ; exit 1' 1 2 3 13 15
trap 'rm -f ${TMPWILD} ; exit 0' 0
# get command-line options # get command-line options
DIRECTION='none' DIRECTION='none'
OPTIMIZE=y OPTIMIZE='y'
TOUCH=n TOUCH='n'
VERBOSE=y VERBOSE='y'
while getopts fhlqrtu opts while getopts fhlqrtu opts
do do
case $opts in case $opts in
f) OPTIMIZE=n ;; f) OPTIMIZE='n' ;;
h) echo 'rot-jpg LU_VERSION' h) echo 'rot-jpg LU_VERSION'
echo 'usage: rot-jpg [-f(ast)] [-h(elp)] [-l(eft)] [-q(uiet)] [-r(ight)]' echo 'usage: rot-jpg [-f(ast)] [-h(elp)] [-l(eft)] [-q(uiet)] [-r(ight)]'
echo ' [-t(ouch)] [-u(pside-down)] JPEG_filename ...' echo ' [-t(ouch)] [-u(pside-down)] JPEG_filename ...'
exit 0 ;; exit 0 ;;
l) DIRECTION='left' ;; l) DIRECTION='left' ;;
q) VERBOSE=n ;; q) VERBOSE='n' ;;
r) DIRECTION='right' ;; r) DIRECTION='right' ;;
t) TOUCH=y ;; t) TOUCH='y' ;;
u) DIRECTION='upsidedown' ;; u) DIRECTION='upsidedown' ;;
*) echo 'rot-jpg LU_VERSION' *) echo 'rot-jpg LU_VERSION'
echo 'usage: rot-jpg [-l(eft)] [-h(elp)] [-o(ptimize)] [-q(uiet)]' echo 'usage: rot-jpg [-l(eft)] [-h(elp)] [-o(ptimize)] [-q(uiet)]'
echo ' [-r(ight)] [-t(ouch)] [-u(pside-down)]' echo ' [-r(ight)] [-t(ouch)] [-u(pside-down)]'
echo ' JPEG_filename ...' echo ' JPEG_filename ...'
exit 1 ;; exit 1 ;;
esac esac
done done
shift `expr ${OPTIND} - 1` shift $((${OPTIND}-1))
if [ "X$DIRECTION" = 'Xnone' ]; then if [ "X$DIRECTION" = 'Xnone' ]; then
echo 'rot-jpg error: direction not specified; use -l, -r, or -u option' echo 'rot-jpg error: direction not specified; use -l, -r, or -u option'
exit 1 exit 1
fi fi
# set up traps
trap 'rm -f $TMPJPG ; exit 1' 1 2 3 13 15
# run through files # run through files
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
# make sure we can read and modify file # make sure we can read and modify file
if [ ! -f "$1" -o ! -r "$1" -o ! -w "$1" ]; then if [ ! -f "$1" -o ! -r "$1" -o ! -w "$1" ]; then
echo "rot-jpg warning: $1 is not a writeable non-directory file" echo "rot-jpg warning: $1 is not a writeable non-directory file"
shift; continue shift; continue
fi fi
# make sure it's a JPEG # make sure it's a JPEG
imagsize "$1" | grep -q 'type=jpg' imagsize "$1" | grep -q 'type=jpg'
OUT="$?" if [ $? -ne 0 ]; then
if [ "$OUT" -ne 0 ]; then
echo "rot-jpg warning: $1 is not a JPEG" echo "rot-jpg warning: $1 is not a JPEG"
shift; continue shift; continue
fi fi
# run through jpegtram # run through jpegtram
TMPJPG=`tempname -s .gif rot-jpg_$$` || exit 99 TMPJPG=$(tempname -s .gif rot-jpg_$$) || exit 99
if [ "X$DIRECTION" = 'Xleft' ]; then if [ "X$DIRECTION" = 'Xleft' ]; then
jpegtran -trim -rotate 270 "$1" > ${TMPJPG} jpegtran -trim -rotate 270 "$1" > $TMPJPG
elif [ "X$DIRECTION" = 'Xright' ]; then elif [ "X$DIRECTION" = 'Xright' ]; then
jpegtran -trim -rotate 90 "$1" > ${TMPJPG} jpegtran -trim -rotate 90 "$1" > $TMPJPG
else else
jpegtran -trim -rotate 180 "$1" > ${TMPJPG} jpegtran -trim -rotate 180 "$1" > $TMPJPG
fi fi
# optimize image to minimize filesize # optimize image to minimize filesize
if [ "$OPTIMIZE" = 'y' ]; then if [ "$OPTIMIZE" = 'y' ]; then
opt-jpg -q ${TMPJPG} opt-jpg -q $TMPJPG
fi fi
# copy back to original filename # copy back to original filename
if [ "$TOUCH" = 'y' ]; then if [ "$TOUCH" = 'y' ]; then
touch -r "$1" ${TMPJPG} touch -r "$1" $TMPJPG
cp --preserve=timestamps ${TMPJPG} "$1" cp --preserve=timestamps $TMPJPG "$1"
else else
cp ${TMPJPG} "$1" cp $TMPJPG "$1"
fi fi
# clean up afterwards # clean up afterwards
rm -f ${TMPJPG} rm -f $TMPJPG
shift shift
done done
rm -f ${TMPWILD}
 End of changes. 19 change blocks. 
27 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)