Gen2ly
March 19th, 2008, 05:01 AM
I admit this is my first loop. From what I've read this is the right way to create a loop but the loop only runs once and quits. I believe this has something to do with the variable-reference.
What I'm looking to do is create a script that I can type
command *.png
and all pngs will be run through the script. Here's the script:
#!/bin/bash
# resize-image-new - makes new image and resizes.
# http://www.imagemagick.org/www/command-line-options.html
# Fixes / ToDo
# add ability to subtract enhance flag
# add looping: resize-new-image 400 *.png
SIZE=$1
NAME=$2
COLORS=2048
DEPTH=16
RESIZEDNAME="${NAME%.*}"-"$SIZE".png
#ENHANCE - options to enhance image -enhance smoothes rough images
if [[ -z $NAME ]]; then
echo "resize-image <WIDTHxHEIGHT> <original-image>"
exit;
fi
# Convert (SIZE is proportional least value is used and only x needs specifid.)
# Compress PNG
for i in "$NAME"; do
convert -resize "$SIZE" -enhance "$NAME" "$RESIZEDNAME"
mogrify -colors $COLORS -depth $DEPTH "$RESIZEDNAME"
optipng -o5 "$RESIZEDNAME"
done
The script works fine by typing:
command picture.png
However specifying *.png will only loop once. What am I notunderstandigng here?
What I'm looking to do is create a script that I can type
command *.png
and all pngs will be run through the script. Here's the script:
#!/bin/bash
# resize-image-new - makes new image and resizes.
# http://www.imagemagick.org/www/command-line-options.html
# Fixes / ToDo
# add ability to subtract enhance flag
# add looping: resize-new-image 400 *.png
SIZE=$1
NAME=$2
COLORS=2048
DEPTH=16
RESIZEDNAME="${NAME%.*}"-"$SIZE".png
#ENHANCE - options to enhance image -enhance smoothes rough images
if [[ -z $NAME ]]; then
echo "resize-image <WIDTHxHEIGHT> <original-image>"
exit;
fi
# Convert (SIZE is proportional least value is used and only x needs specifid.)
# Compress PNG
for i in "$NAME"; do
convert -resize "$SIZE" -enhance "$NAME" "$RESIZEDNAME"
mogrify -colors $COLORS -depth $DEPTH "$RESIZEDNAME"
optipng -o5 "$RESIZEDNAME"
done
The script works fine by typing:
command picture.png
However specifying *.png will only loop once. What am I notunderstandigng here?