Labels

Monday, November 14, 2011

Image Resize, Thumbnail Generation

Use Perl to resize images to thumbnail size.  Helpful when you are supporting websites with a TON of images.
Requires Image::Magick


#!/usr/bin/perl
#Name:  thumbgen.pl
#Desc:  Generate thumbnail sized images from full product images.
#Author:  Rob Owens
##Change##
#initial:rowens/100411
#
#Notes:
#Development Env:
#ImageRoot:/var/www/html/images
#Full:/var/www/html/images/full
#Thumb:/var/www/html/images/thumb
#
#estore.savtira.net width=70
#
# PerlMagick Method(s)
#my($image, $x);
#
#$image = Image::Magick->new;
#$x = $image->Read('Blood_for_Blood_God_by_NachoMon.jpg');
#warn "$x" if "$x";
#
#$x = $image->Resize(geometry=>'70x');
#warn "$x" if "$x";
#
#$x = $image->Write('Blood_thumb.jpg');
#warn "$x" if "$x";
#
#
#
#my $FullDir = "/var/www/html/images/full";
use Image::Magick;
require './lib/imagelib';


#my $FullDir = '/home/rowens/repos/imageresize/html/images/full';
#my $ThumbDir = '/home/rowens/repos/imageresize/html/images/thumb';


my $FullDir = $ARGV[0];
my $ThumbDir = $ARGV[1];
my $size = $ARGV[2];
my $x = x;


if (( $FullDir eq '' ) || ( $ThumbDir eq '' )) {
        usage(basic);
        exit 1;
} elsif ( ! -e $FullDir ) {
        usage(source);
        exit 1;
} elsif ( ! -e $ThumbDir ) {
        usage(target);
        exit 1;
} 
if ( $size eq '' ) {
        $Resize = '70x';
} else {
        $Resize = $size . $x;
}


opendir(D, "$FullDir") || die "Can't opedir $FullDir: $!\n";
while ( my $file  = readdir(D) ) {
# remove "." and ".." directories
        next if ( $file =~ m/^\./ );
# only files
        next if ( -d "$FullDir/$file" );
# all images into an array
        push ( @tmpfull, "$file" );
}
closedir(D);


#print "@full";






foreach $tmpfile (@tmpfull) {
#       printf "PRE:  $ThumbDir/$tmpfile\n";
        next if ( -e "$ThumbDir/$tmpfile");
#       printf "PST:  $ThumbDir/$tmpfile\n";
        push(@full, "$tmpfile");
}
#
foreach $file (@full) {
        resize("$FullDir/$file","$ThumbDir/$file","$Resize"); 
}

# ./lib/imagelib
#use Image::Magick

my ($image, $x);
$image = Image::Magick->new;

sub resize {
        $infile = $_[0];
        $outfile = $_[1];
        $resize = $_[2];
        my($image);

        $image = Image::Magick->new;

        $image->Read($infile);

        $image->Resize(geometry=>$resize);

        printf "Resizing image:   $infile\n";

        $image->Write($outfile);

return 0;
} print;

sub usage {
        $err = $_[0];
        if ( $err =~ /source/ ) {
                printf "Error:  Source Directory doesn't exist\n";
                printf "Usage:  thumbgen <source_directory> <target_directory> [pix width]\n\n";
        } elsif ( $err =~ /target/ ) {
                printf "Error:  Target Directory doesn't exist\n";
                printf "Usage:  thumbgen <source_directory> <target_directory> [pix width]\n\n";
        } elsif ( $err =~ /basic/ ) {
                print<<EOF;
Thumb Generator:  Used to generate thumbnails.  Shrinking width size while
maintaining scale.
Usage:  thumbgen <source_directory> <target_directory> [pix width]
        Example(s):
        Resize original images to thumbnail size, using default 70px wide: 
        thumbgen /var/www/html/images/full /var/www/html/images/thumb

        Resize original images to thumbnail size, specifying 100px width:
        thumbgen /var/www/html/images/full /var/www/html/images/thumb 100

        NOTE!  Program maintains the filename, hence output directory.

EOF
        }

return 1;
} print;

Wednesday, October 19, 2011

Linux Remote Password Changes

1.  For remote password changes, you'll need sudo rights on the remote.

2.  Ensure sudo is configured for remote root commands.

  a. Edit /etc/sudoers with  visudo

  b. comment out the following:

  #Defaults    requiretty
  #Defaults   !visiblepw

3.  Generate a new password for the user using this simple perl thingie:
Example:
[doomicon@songohan tools]$ ./genpass.pl password
$1$m/Ba1kqd$LXQxR..lqUwgWE5kSPESF0

#!/usr/bin/perl
#
# usage:  genpass.pl '<password>'
# Generate MD5 encrypt string for remote useradd/usermod
# rowens
#"THE BEER-WARE LICENSE" (Revision 42):
# <
phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp

use Crypt::PasswdMD5;
my @salt = ( '.', '/', 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );


$newpass="$ARGV[0]";
sub gensalt {
        my $count = shift;
        my $salt;
                for (1..$count) {
                        $salt .= (@salt)[rand @salt];
                }

return $salt;
}

$encryptpass = unix_md5_crypt( $newpass, gensalt(8) );
printf "$encryptpass\n";

4.  Using the password just generated, we'll use the nifty '-p' option for usermod.

ssh remote_host sudo /usr/sbin/usermod -p '$1$m/Ba1kqd$LXQxR..lqUwgWE5kSPESF0' remoteuser

If you have to change this user on multiple hosts, just loop it.

for host in `grep -v ^127 /etc/hosts | awk '{ print $1 }'`
do
ssh $host sudo /usr/sbin/usermod -p '$1$m/Ba1kqd$LXQxR..lqUwgWE5kSPESF0' user
done

Fin

Wednesday, August 24, 2011

Sailing Again

Did some more sailing two Saturdays ago, last Saturday wind was "poo" so we ate lunch on the boat and kids and I dove in to clean the bottom.

My Beautiful Wife!
I'm on a boat... 

Alex a friend of my son, came along for the ride :-)
Lately the wind has been pretty poor, hoping to get out this Saturday morning, as with Hurricane Irene roaming about, the wind is expected to be pretty good ;-)

Sunday, August 14, 2011

Catching Up... Boat Move

Well Summer has been a busy one!  Many Birthdays, a family vacation, moving a sailboat, new job, and an anniversary :-)

I haven't had the time to post much, so I will be trying to catch up.

First thing this summer was purchasing a sailboat.  I boat a 1973 Grampian 26' boat FOR CHEAP!!!  When I told a childhood friend of mine how much I paid his response was, "I PAID MORE FOR MY CROWNS AT THE DENTIST!  Your telling me I could've purchased a sailboat!"

YES!  I've been looking at sailboats for about 5 years, and with the down economy I've watched the prices of used boats plummet!  Craigslist, Yachtworld, you name it.  Check the sites, and you'd be surprised what you can find for under $5000.  It will require some elbow grease, but you can find sturdy sailboats, that can be made better with a little work.

So on to the boat, I present "Yellow Bird"  .. ya I know name is .. uhm well.. it will be changed.

I stumbled across this little boat on Craigslist.  The entire family drove down to Punta Gorda, FL to purchase.

Sam During the Purchase


Boat is purchased.. now.. I have to find a crew and sail her 100 nm!

Loading up and preparing to go...

Travis and Ce, crewmates in the foreground, mah girl Aileen in the background


Heading out.. Crew:  Travis, Ce and Myself.. two days of sailing.

Finally out of Charlotte Harbor, time to sail...
Travis Taking the Helm err.. Tiller
No wind :-(  Now we're motoring
more to come!!

Wednesday, August 3, 2011

Thursday, June 30, 2011

Busy, Busy, Busy

My apologies for not updating the blog, however things have been quite hectic.  I purchased a sailboat; which I have to sail from Punta Gorda to St. Petersburg.  I landed a new job "Praise God", and did a 15 mile hike with my son.

Lastly readying a 5 day family vacation to Key Largo.

All this running around, and fulfilling obligations work and otherwise has put me behind on getting my stuff up for sale.

Hopefully, I will soon get the opportunity to catalog everything and get it listed for sale.

If you follow this blog, and have a rough idea what I have, just send me an offer.  No reasonable offers refused.