<?php

require 'vendor/autoload.php'; # Composer
# require_once 'Browshot.php'; # or download Browshot.php

$browshot = new Browshot('my_api_key');

$screenshot = $browshot->screenshot_create(array('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'} != 'finished' &&  $screenshot->{'status'} != 'error') {
	echo "Wait...\n";
	sleep(10);
	$screenshot = $browshot->screenshot_info($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($screenshot->{'id'}, "google-1.png", array('zoom' => 33));
echo "Thumbnail saved to google-1.png\n";

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

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

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

?>