<?php

#######################
# WARNING
# Running this code sample will cost you Browshot credits
#######################

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

$browshot = new Browshot('my_api_key');


$crawl = $browshot->crawl_create(array('url' => 'https://blitapp.com/', 'domain' => 'blitapp.com', max => 25, instance_id' => 65, 'screen_width' => 1600, 'screen_height' => 1200, 'size' => 'page')); # Get full size thumbnails
if ($crawl->{'status'} == 'error') {
	echo sprintf("Crawl failed: %s\n", $crawl->{'error'});
	exit(0);
}

echo sprintf("Crawl #%d in process\n", $crawl->{'id'});

sleep(30);
while ($crawl->{'status'} != 'finished' && $crawl->{'status'} != 'error') {
	sleep(15);
	$crawl = $browshot->crawl_info($crawl->{'id'});
}

if ($crawl->{'status'} == 'error') {
	echo sprintf("Crawl failed: %s\n", $crawl->{'error'});
	exit(0);
}

# The crawl succeeded, download the thumbnails.
foreach ($crawl->{'urls'} as $screenshot) {
	echo "Downloading $url...\n";
	# download the URL
  $browshot->screenshot_thumbnail_file($screenshot->{'id'}, "file-" . $screenshot->{'id'} . ".png", array('right' => 768, 'bottom' => 768, 'height' => 300, 'width' => 300, 'ratio' => 'fit'));
}


?>