#############################################################################
# Yahoo Image Search Wallpaper Generator
#
# Written by Shubham Singal
# shubham@gmail.com
#
# ############################################################################
use strict;
use warnings 'all';
use Getopt::Long;
use LWP::Simple;
use constant AppUrl => "http://upster.blogspot.com/2005/03/" .
"yahoo-image-search-collage-generator.html";
use Yahoo::Search AppId => "wallpaper_maker";
my $rows = 10;
my $columns = 10;
my $total = $rows * $columns;
my $width = 80;
my $height = 60;
my $query = "";
my $help = 0;
GetOptions(
'query=s' => \$query,
'rows=i' => \$rows,
'columns=i' => \$columns,
'width=i' => \$width,
'height=i' => \$height,
'help' => \$help,
);
if ($help) {
print qq/$0
--query
[--rows
[--columns
[--width
[--height
[--help] Displays this message/;
exit;
}
die "Must specify a query!\n" unless ($query);
my $folder = "folder_to_store_temp_images";
if(-d $folder)
{
system("rm -rf $folder");
}
system("mkdir $folder");
my $i=0;
print "Querying Yahoo...";
while($total>0)
{
my @results = Yahoo::Search->Results(
Image => $query,
Count => 50,
Start => $i
);
print "\n Query DONE!\n";
my $size = $width."x".$height;
foreach (@results)
{
my $url = $_->ThumbUrl() ;
if (getstore($url, "$folder/$i.jpg") eq 200)
{
system("convert $folder/$i.jpg -resize $size $folder/resize_$i.jpg ");
print " $i";
$i++;
}
}
$total = $total - 50;
}
$i--;
print "\n Creating Wallpaper\n";
my $rc = $rows."x".$columns;
system("montage $folder/resize_*.jpg -tile $rc -geometry +2+2 Wallpaper_$query.jpg");
if(-d $folder)
{
system("rm -rf $folder");
}
print "\n Wallpaper Created\n";
No comments:
Post a Comment