Facebook Photo Decompression

Script to perform photo compression:

I wrote this script to auto-compress the huge images that my daughter downloads from our digital camera and uploads to Facebook.  It automatically reduces any new image added to ~/images/Facebook/ by about 85%.  I include it in a shell-script that first invokes gthumb (the program she uses to download and view photos) so that when gthumb exits, this script is invoked.



=head1 NAME

compressForFacebook.pl – Compress all jpeg files in $HOME/images/Facebook/ using mogrify().




Compresses all jpeg files in $HOME/images/Facebook/ using mogrify() that have been
created or modified since the last run, time of which is stored in

Reasonably expectable results are approximately 87% compression w/o noticable loss of
visible picture quality.  Written by Jim Turner to reduce upload times to Facebook.
Intended use:  Include in batch file to run with and after graphical image
download program when downloading pictures from a camera.

Copyright(c) 2009, by Jim Turner
Licensed under the GNU LGPL Opensource license.


my $realpath = “$ENV{HOME}/images/Facebook”;

my $lastRunTime = 0;
if (open F, “$ENV{HOME}/.compressForFacebook.lastrun.txt”)
$lastRunTime = <F>;
close F;
chomp $lastRunTime;

if (opendir D, $realpath)
while ($t = readdir(D))
$_ = $realpath . ‘/’ . $t;
@statInfo = stat;
if (/\.jpe?g$/io && -f $_ && $statInfo[9] > $lastRunTime)
print STDERR “–compressing file $t…\n”;
`mogrify -compress JPEG -quality 50 $_`;
closedir D;
$lastRunTime = time;
if (open F, “>$ENV{HOME}/.compressForFacebook.lastrun.txt”)
print F “$lastRunTime\n”;
close F;





One Trackback

Feel Free to Comment (Name/Email/Website optional):

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: