All pastes #179444 Raw Edit

codemac

public shellscript v1 · immutable
#179444 ·published 2006-09-22 06:37 UTC
rendered paste body
#!/bin/bash## $ Id: image2ascii,v 1.6 2002/12/01 12:36:56 roland Exp roland $## Convert any image to an ASCII-graphic using ImageMagick#############################################################################   Copyright (C) 1997-2002  Roland Rosenfeld <roland@spinnaker.de>##   This program 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 Software Foundation; either version 2 of#   the License, or (at your option) any later version.##   This program is distributed in the hope that it will be useful,#   but WITHOUT ANY WARRANTY; without even the implied warranty of#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU#   General Public License for more details.##   You should have received a copy of the GNU General Public License#   along with this program; if not, write to the Free Software#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.###########################################################################CONVERT=convert		# The ImageMagick convert binaryPBMTOASCII=pbmtoascii	# The NetPBM pbmtoascii binaryumask 077tmpdir=${TMPDIR-/tmp}/image2ascii.$$mkdir $tmpdir || exit 1trap "rm -rf $tmpdir; exit" 0 1 2 3 15TMPFILE=$tmpdir/imageusage="Usage: $0 [option] [imagefile]   -help                display this help text   -geometry 132x50     define the size of the ascii image"# set default geometry to display width:geometry=`stty size </dev/tty | awk '{print $2 "x" $1}'`# test if stty did not output a useful value:case "$geometry" in        0x0 ) geometry=80x24 ;;        ""  ) geometry=80x24 ;;esaccase $# in         0 ) cat > $TMPFILE ;;        1 ) case "$1" in                    -* ) echo "$usage"; exit 0 ;;                    * )  cat "$1" > $TMPFILE ;;            esac ;;        2 ) case "$1" in                    -geometry ) geometry=$2                                cat > $TMPFILE ;;                    * )         echo "$usage"; exit 0 ;;            esac ;;        3 ) case "$1" in                    -geometry ) geometry=$2                                cat $3 > $TMPFILE ;;                    * )         echo "$usage"; exit 0 ;;            esac ;;        * ) echo "$usage"; exit 0 ;;esac# multiply x with 2 and y with 4 (pbmtoascii divides by 2x4)geometry=`echo $geometry | awk -Fx '{print 2*$1 "x" 4*$2}'`$CONVERT -geometry $geometry $TMPFILE $TMPFILE.pbm$PBMTOASCII -2x4 < $TMPFILE.pbm