Skip to content. | Skip to navigation

Personal tools
Log in Register
Sections
You are here: Home Uploads projects files pngtogif pngtogif

pngtogif

#!/bin/bash #pngtogif 1.0 #copyright 2002 Manuel Amador (Rudd-O). This software is under the GPL #http://www.usm.edu.ec/~amadorm/ if [ "$1" == "" ] ; then echo "pngtogif 1.0 by Rudd-O." echo "converts each PNG file specified in the command line to a GIF file with the same name" echo "preserving transparency and quantizing colors if required" echo "(all transparent GIF files have a cyan transparency mask)" echo echo "This software requires the full NetPBM utilities to be installed" echo echo "This software is under the GPL. NO WARRANTY WHATSOEVER." echo echo 'usage: $0 [file2 file3...]' exit 2 fi tesst=`which pngtopnm 2> /dev/null` if [ "$tesst" == "" ]; then echo "You don't have the NetPBM utilities installed" exit 1 fi tesst=`which ppmtogif 2> /dev/null`` if [ "$tesst" == "" ]; then echo "You don't have the NetPBM utilities installed" exit 1 fi tesst=`which ppmquant 2> /dev/null`` if [ "$tesst" == "" ]; then echo "You don't have the NetPBM utilities installed" exit 1 fi until [ "$1" == "" ] ; do dn=`dirname "$1"` fn=`basename "$1"` ofn=`echo $fn | sed 's/.png$/.gif/g' | sed 's/.PNG$/.GIF/g' ` if [ "$ofn" == "$fn" ]; then ofn="$fn.gif" fi if [ "$dn" == "." ] ; then filename="$fn" dest="$ofn" else filename="$dn/$fn" dest="$dn/$ofn" fi ppm=`mktemp /tmp/ppm.XXXXXX` || exit 1 pgm=`mktemp /tmp/pgm.XXXXXX` || exit 1 pgmquant=`mktemp /tmp/pgmquant.XXXXXX` || exit 1 ppmquant=`mktemp /tmp/ppmquant.XXXXXX` || exit 1 if [ -s "$filename" ]; then echo -n "converting $filename... " > /dev/stderr pngtopnm "$filename" > "$ppm" 2> /dev/null pngtopnm -alpha "$filename" > "$pgm" 2> /dev/null ppmtogif -alpha="$pgm" -alphacolor=cyan < "$ppm" > "$dest" 2> /dev/null if [ -s "$dest" ] ; then echo "success!" > /dev/stderr else echo -n "quantizing... " > /dev/stderr ppmquant 255 < "$ppm" > "$ppmquant" 2> /dev/null ppmtogif -alpha="$pgm" -alphacolor=cyan < "$ppmquant" > "$dest" 2> /dev/null if [ -s "$dest" ] ; then echo "success!" > /dev/stderr else echo "failed" > /dev/stderr fi fi rm -f "$ppm" "$pgm" "$pgmquant" "$ppmquant" else echo "$filename is not a PNG file... skipping..." > /dev/stderr fi shift done exit 0
Document Actions