Skip to content

Instantly share code, notes, and snippets.

@erangaeb
Created June 25, 2016 15:03
Show Gist options
  • Save erangaeb/9489c11757cfd619c73b50c20c234aa9 to your computer and use it in GitHub Desktop.
Save erangaeb/9489c11757cfd619c73b50c20c234aa9 to your computer and use it in GitHub Desktop.
shell script to compress images
#!/bin/bash
# A script to resize images.
readonly OUT_FMT="_new.jpg"
if [ "$#" -eq 0 ] ; then
echo "A script to resize images "
echo "How to use : $(basename $0) add_of_image1 add_of_image2 ..."
exit 1
fi
for pic
do
# New filename
out_name="${pic%.*}$OUT_FMT"
if [ -e "$out_name" ] ; then
echo "Output file $out_name exists, Not resizing!!!"
elif [ "${pic#*$OUT_FMT}" == "" ] ; then
echo "$pic already resized!!!"
elif [ ! -r "$pic" ] ; then
echo "Error : could not access $pic !!!"
else
echo -n "$pic -> $out_name"
convert -quality 70 -resize 1600X1200 "$pic" "$out_name"
if [ ! -e "$out_name" ] ; then
echo " Error .. No output file!!!"
else
echo " ($(du -h "$out_name" | cut -f1))"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment