PHP

Sample code to take website screenshots in PHP

Check out our composer package here, and on github

// run this on the command line to install the urlbox php package:
// composer require urlbox/screenshots
use Urlbox\Screenshots\Urlbox;
$urlbox = Urlbox::fromCredentials('API_KEY', 'API_SECRET');
// only required option is a url:
$options['url'] = 'example.com';
// specify any other options to augment the screenshot...
$options['width'] = 320;
// Create the Urlbox URL
$urlboxUrl = $urlbox->generateUrl($options);
// $urlboxUrl is now 'https://api.urlbox.io/v1/API_KEY/TOKEN/png?url=example.com&width=320'
// Generate a screenshot by loading the Urlbox URL in an img tag:
echo '<img src="'.$urlboxUrl.'" alt="Test screenshot generated by Urlbox">'
Was this page helpful?