#! /usr/local/bin/perl -w
######program takes in keywords file and puts images in dir images/ and creates file Im
ageData with all the data for the images.
use strict;
use warnings 'all';
use Getopt::Long;
use LWP::Simple;
use Yahoo::Search AppId => "shubh_iitd";
my $i=0;
open(FILEREAD, "keywords");
open(FILEWRITE, ">ImageData");
while (
print " word is: $_";
my $query=$_;
my @results = Yahoo::Search->Results(
Image => $query,
Count => 10
);
foreach (@results) {
my $url = $_->Url();
print "\n $i - $url";
if (getstore($url, "images/$i.jpg") eq 200){
my $im = 0;
open(IN, "images/$i.jpg");
binmode(IN);
read(IN,$b,4);
my $s = 2*length($b);
my $ch = unpack("H$s", $b);
print "\n |$ch| ";
if($ch eq "ffd8ffe0") {print " JPEG ";$im=1;}
if($ch eq "47494638") {print " GIF ";$im=1;}
if($ch eq "89504e47") {print " PNG ";$im=1;}
if($ch eq "4d4d002a") {print " TIFF Big Endian ";$im=1;}
if($ch eq "49492a00") {print " TIFF Little Endian ";$im=1;}
if($ch =~ /^424d/) {print " BMP ";$im=1;}
close(IN);
if($im eq 1){
$i++;
print FILEWRITE "$i.jpg - $url - $query\n";
}
}
}
}
close FILEREAD;
close FILEWRITE;
Tuesday, June 14, 2005
Store Images using Yahoo! API
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment