As usual, I have learned a lot from your replies. Thanks.
dragonchild, I never got a chance to test it, only post this question, as I had my son on my lap ;-) He's now in bed, so I can reply.
The reason I posted this, is because I am going back to my old programs after learning more, and trying to make them clean and have less code.
The program in question was written for my wife, as she always asks me how to resize images and upload them to ebay. I wrote this, called ebaypics, which is then saved in ~/.gnome2/nautilus-scripts she then right clicks in the folder she has the photos in, and that's it.
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
use Mail::Sendmail;
use Image::Magick;
use Term::ProgressBar;
#################################################
# program: ebaypics #
# license: GPL #
# author: Gavin Henry #
# #
# version: v0.1 #
# #
# first draft : 22-09-04 #
# last update : 27-09-04 #
#################################################
my @images = <*.jpg>;
my $resize = '640x480';
my ($image,$process);
my $ftpsite = 'ftp.somewhere.net';
my $website = 'http://www.somewhere.com/ebay';
my $remotedir = '/htdocs/ebay';
my $username = 'user';
my $password = 'pass';
my $to = '"My name" <my.name@me.co.uk>';
my $from = '"ebaypics" <ebaypics@me.com>';
my $sep = '-' x 76 . "\n";
my $time = localtime;
my $progress = Term::ProgressBar->new({name => 'Scaling images',
count => scalar @images,
ETA => 'linear'});
# Messages
print "\n", $sep, "Starting....\n", $sep;
&resize;
my @thumbs = <thumbnail-*.jpg>;
# Get pictures and upload
my $ftp = Net::FTP->new("$ftpsite",
Timeout => 30)
or die "Sorry I can't connect: $@\n";
$ftp->login($username, $password)
or die "Wrong password. Please call Gavin.\n";
$ftp->cwd("$remotedir");
foreach (@thumbs) {
$ftp->put($_)
or die "Can't find the resized pictures: $!\n";
}
$ftp->quit()
or warn "Couldn't quit. Damn.\n";
my @email_links = links($website, @thumbs);
my %mails = (
To => "$to",
From => "$from",
Subject => "Here are the links to your pictures",
Message => "Click on any of the links below to check the pictures"
+
. " are correct, then copy and paste them into your"
. " ebay listing.\n\n"
. " Weblinks:\n"
. " @email_links\n\n"
);
sendmail(%mails);
print "\n", $sep, "Resizing of images complete at $time. E-mail sent w
+ith website links.\n", $sep;
# Subroutines
sub resize {
print "\n", $sep, "Resizing images.....this may take some time....
+.\n", $sep;
foreach (@images) {
$image = Image::Magick->new();
$process = $image->Read("$_");
$process = $image->Resize(geometry => "$resize");
warn "$process" if "$process";
$process = $image->Write("thumbnail-$_");
warn "$process" if "$process";
$progress->update();
}
print "\n", $sep, "Resizing complete, starting upload to webspace.
+....\n", $sep;
}
# Generate weblinks
sub links {
my ($url, @list) = @_;
my @return;
foreach (@list) {
push @return, "$url/$_\n";
}
return @return;
}
Needs a bit of work ;-)
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.