#!/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 $from = '"ebaypics" '; 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 = ; # 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 with 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; }