Published on Saturday, February 16th, 2008 at 2:35 pm

This little snippet is a script I have running via Cron, set to execute every 30 minutes.  If like me, you have maybe running forum software that isnt so great handling image uploads in posts and find that users complain because they themselves arent too sure how to resize images prior to posting then this may be useful.

What it does is scan a specified folder every 30 minutes(as set by cron) for new uploaded jpg’s that are greater than a specified size.  Using the ImageMagick libraries, it then applies compression and resizes proportionally the image if it exceeds a specified height & width.  Images which have been uploaded as 2Mb originals have been processed and saved as 20k files, thats 1% of the original size without any real noticable difference in quality.  People tend to upload images which are suitable for professional printing and far exceed the quality required for simple website viewing.

This is my code:

DATETIME=`date +%d-%m-%Y-%H:%M`
echo "Looking for files in : $src_dir on $DATETIME"
#find $src_dir -iname '*.jp*g' -size +100k -mmin -30
for i in `find $src_dir -iname '*.jp*g' -size +256k` ;
echo "Processing : "$i
convert -resize 1024x768\> -quality 80 $i $i;
Be Sociable, Share!

Related Posts

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

About Me

Welcome to my blog. Here you'll find mainly work related content, a suppository for all my notes which otherwise would end up on a post it note.