You can install WebService::Browshot from CPAN. The source code is available on gitbub.
Here are a couple of basic code samples.
use WebService::Browshot;
my $browshot = WebService::Browshot->new(key => 'my_key');
my ($code, $file) = $browshot->simple_file(url => 'http://www.google.com/', file => '/tmp/google.png');
if ($file eq '' || $code != 200) {
print "Screenshot failed\n";
}
else {
print "Screenshot saved at $file\n";
}
use WebService::Browshot;
my $browshot = WebService::Browshot->new(key => 'my_key');
my $screenshot = $browshot->screenshot_create(url => 'http://www.google.com/');
# wait until screenshot is done
sleep 5;
my $status = $browshot->screenshot_info(id => $screenshot->{id});
while ($status->{status} ne 'finished' && $status->{status} ne 'error') {
sleep 1;
$status = $browshot->screenshot_info(id => $screenshot->{id});
}
# screenshot failed?
if ($status->{status} eq 'error') {
print "Screenshot failed\n";
exit(0);
}
$browshot->screenshot_thumbnail_file(url => $status->{screenshot_url}, file => '/tmp/google.png'); # no width/height/scale mentioned, full screenshot retrieved
print "Screenshot was saved to /tmp/google.png\n";
use WebService::Browshot;
my $browshot = WebService::Browshot->new(key => 'my_key');
my ($code, $file) = $browshot->simple_file(url => 'http://www.google.com/', file => '/tmp/google-640.png', width => 640, height => 480);
if ($file eq '' || $code != 200) {
print "Screenshot failed\n";
}
else {
print "Thumbnail saved at $file\n";
}
use WebService::Browshot;
my $browshot = WebService::Browshot->new(key => 'my_key');
my $screenshot = $browshot->screenshot_create(url => 'http://www.google.com/');
# wait until screenshot is done
sleep 5;
my $status = $browshot->screenshot_info(id => $screenshot->{id});
while ($status->{status} ne 'finished' && $status->{status} ne 'error') {
sleep 1;
$status = $browshot->screenshot_info(id => $screenshot->{id});
}
# screenshot failed?
if ($status->{status} eq 'error') {
print "Screenshot failed\n";
exit(0);
}
$browshot->screenshot_thumbnail_file(url => $status->{screenshot_url}, file => '/tmp/google-640.png', width => 640, height => 480);
print "Screenshot was saved to /tmp/google-640.png\n";