<?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');


$data = $browshot->simple(array('url' => 'http://mobilito.net/', 'instance_id' => 12)); # default cache, free screenshot
# code above is blocking, it will return when the screenshot finished or failed

if ($data['code'] == "200") { # success
	$fp = fopen("screenshot.png", 'w');
	fwrite($fp, $data['image']);
	fclose($fp);

	echo "Screenshot saved to screenshot.png\n";
}
else {
	echo "Screenshot failed!\n";
	# the reason for the error is sent as part of the HTTP response in the X-Error header but it is not exposed by this library
}



# quicker way to save a screenshot
$info = $browshot->simple_file('mobilito.png', array('url' => 'http://mobilito.net/', 'cache' => 0, 'instance_id' => 65, 'screen_width' => 1280, 'screen_height' => 1024)); # no cache, premium browser

if ($info['file'] != "") {
  echo sprintf("Screenshot saved to %s\n", $info['file']);
}
else {
  echo "The screenshot failed\n";
}


# use the default cache. The previous screenshto will be returned (same parameters) except if the previous failed
$info = $browshot->simple_file('mobilito-2.png', array('url' => 'http://mobilito.net/', 'instance_id' => 65, 'instance_id' => 65, 'screen_width' => 1280, 'screen_height' => 1024, 'width' => 200)); # thumbnail
if ($info['file'] != "") {
	 echo sprintf("Screenshot saved to %s\n", $info['file']);
}
else {
	echo "The screenshot failed\n";
}

# host a screenshot on S3
$info = $browshot->simple_file('mobilito-2.png', array(
	'url' => 'http://mobilito.net/',  
	'instance_id' => 65, 
	'screen_width' => 1280,
	'screen_height' => 1024,
	'hosting' => 's3',
	'hosting_bucket' => 'my_bucket',
	'hosting_file' => 'youtube.png',
	'hosting_width' => 200 # thumbnail
));


?>