"Fossies" - the Fresh Open Source Software Archive

Member "littleutils-1.2.4/scripts/opt-gif.in" (28 Mar 2021, 2254 Bytes) of package /linux/privat/littleutils-1.2.4.tar.lz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "opt-gif.in": 1.2.3_vs_1.2.4.

    1 #! PROGBASH
    2 # vim: set filetype=bash:
    3 
    4 # opt-gif: Recompresses .gif files
    5 
    6 # Copyright (C) 2004-2021 by Brian Lindholm.  This file is part of the
    7 # littleutils utility set.
    8 #
    9 # The opt-gif utility is free software; you can redistribute it and/or modify
   10 # it under the terms of the GNU General Public License as published by the Free
   11 # Software Foundation; either version 3, or (at your option) any later version.
   12 #
   13 # The opt-gif utility is distributed in the hope that it will be useful, but
   14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   16 # more details.
   17 #
   18 # You should have received a copy of the GNU General Public License along with
   19 # the littleutils.  If not, see <https://www.gnu.org/licenses/>.
   20 
   21 # get command-line options
   22 TOUCH='n'
   23 VERBOSE='y'
   24 while getopts hqt opts
   25 do
   26   case $opts in
   27     h) echo 'opt-gif LU_VERSION'
   28        echo 'usage: opt-gif [-h(elp)] [-q(uiet)] [-t(ouch)] GIF_filename ...'
   29        exit 0 ;;
   30     q) VERBOSE='n' ;;
   31     t) TOUCH='y' ;;
   32     *) echo 'opt-gif LU_VERSION'
   33        echo 'usage: opt-gif [-h(elp)] [-q(uiet)] [-t(ouch)] GIF_filename ...'
   34        exit 1 ;;
   35   esac
   36 done
   37 shift $((${OPTIND}-1))
   38 
   39 # set up traps
   40 trap 'rm -f $TMPGIF ; exit 1' 1 2 3 13 15
   41 
   42 # run through files
   43 declare -i S0=0 S1=0
   44 while [ $# -gt 0 ]; do
   45 
   46   # make sure we can read and modify file
   47   if [ ! -f "$1" -o ! -r "$1" -o ! -w "$1" ]; then
   48     echo "opt-gif warning: $1 is not a writeable non-directory file"
   49     shift; continue
   50   fi
   51 
   52   # make sure it's a GIF
   53   imagsize "$1" | grep -q 'type=gif'
   54   if [ $? -ne 0 ]; then
   55     echo "opt-gif warning: $1 is not a GIF"
   56     shift; continue
   57   fi
   58 
   59   # run through gifsicle
   60   TMPGIF=$(tempname -s .gif opt-gif_$$) || exit 99
   61   gifsicle --careful -O3 --no-warnings < "$1" > $TMPGIF
   62 
   63   # ensure that new file is smaller
   64   if [ "$TOUCH" = 'y' ]; then
   65     touch -r "$1" $TMPGIF
   66   fi
   67   S0=$(filesize "$1")
   68   S1=$(filesize $TMPGIF)
   69   if [ $S1 -lt $S0 ]; then
   70     cp --preserve=timestamps $TMPGIF "$1"
   71     if [ "$VERBOSE" = 'y' ]; then
   72       echo "$1: $S0 vs. $S1"
   73     fi
   74   else
   75     if [ "$VERBOSE" = 'y' ]; then
   76       echo "$1: unchanged"
   77     fi
   78   fi
   79 
   80   # clean up afterwards
   81   rm -f $TMPGIF
   82   shift
   83 
   84 done