#!/usr/bin/perl -w

use strict;
use warnings;
use Carp;

use WebService::Browshot;

my $browshot = WebService::Browshot->new(
	key	=> 'my_api_key',
	debug	=> 0, # no more debug information
);

my $screenshot = $browshot->screenshot_create(url => 'http://www.google.com/', instance_id => 12); # all default parameters, instance_id = 12 (free)
# If the screenshot is already in cache, it could be finished already. Othwewise, wait longer
while ($screenshot->{status} ne 'finished' &&  $screenshot->{status} ne 'error') {
	print "Wait...\n";
	sleep 10;
	$screenshot = $browshot->screenshot_info(id => $screenshot->{id});
}

# You can request multiple thumbnails of the same screenshot at no cost
# Get a thumbnail at 1/3 (33%) of the original
$browshot->screenshot_thumbnail_file(id => $screenshot->{id}, zoom => 33, file => "google-1.png");
print "Thumbnail saved to google-1.png\n";

# Get a thumbnail with a height of 100 pixels
$browshot->screenshot_thumbnail_file(id => $screenshot->{id}, height => 100, file => "google-2.png");
print "Thumbnail saved to google-2.png\n";

# Get a thumbnail of 200 by 100 pixels at most
$browshot->screenshot_thumbnail_file(id => $screenshot->{id}, height => 100, width => 200, file => "google-3.png");
print "Thumbnail saved to google-3.png\n";

# Crop the screenshot to 768x768, scale it to a 300x300 thumbnail
$browshot->screenshot_thumbnail_file(id => $screenshot->{id}, right => 768, bottom => 768, height => 300, width => 300, ratio => 'fit', file => "google-4.png");
print "Thumbnail saved to google-4.png\n";