DBWS.NET

Automated Website Image Resizing

By admin on Saturday, 16 of February , 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:

#!/bin/bash
src_dir="/var/www/ukordinance/images/fbfiles/images"
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` ;
do
echo "Processing : "$i
convert -resize 1024x768\> -quality 80 $i $i;
done

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • DotNetKicks
  • Slashdot

Leave a comment

Category: Linux

About...

I am David Brown, a freelance software & website developer with an endless passion for learning. I am blessed with a wonderful wife and 3 fantastic children. I am one of rare brits who couldnt care less about soccer but loves diving, surfing & windsurfing.