wrote:
> Hi
>
> Im trying to grab an external image (through url) and save it locally
> on the server. Im using image::grab like so:
>
>
> use Image::Grab;
> $pic = new Image::Grab;
> $pic->url('http://groups.google.com/groups/img/groups_medium.gif');
> $pic->grab;
>
> open(IMAGE, ">$serverpath");
> binmode IMAGE;
> print IMAGE $pic->image;
> close IMAGE;
>
> This saves a file on the $serverpath location but it keeps being
> nothing eg 0k. I remember Ive ran into this previously some time.
>
> Any suggestions??..
I don't know the module so I'll assume your code is ok.
The obvious problem to me is that google block certain useragents, I
don't know what useragent the module declares itself to be, but it's
probably blocked, as is LWP::Simple (libwww-perl/x.xxx).
You'll need to set the useragent to something a browser would use.
$ perl -MLWP::Simple -e 'print length
get("http://groups.google.com/groups/img/groups_medium.gif")'
0
$ perl -MLWP::UserAgent -e 'my $ua = LWP::UserAgent->new( agent =>
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; CS.v0.2; .NET CLR
1.0.3705)" );my
$res=$ua->get("http://groups.google.com/groups/img/groups_medium.gif");print
length $res->content;'
5183
--
Brian Wakem
Email:
http://homepage.ntlworld.com/b.wakem/myemail.png