You will need a Urlbox account to use this package. Please signup here and get your API Key and Secret from the Urlbox dashboard once you have logged in.
Here is a sample call to generate a Urlbox screenshot URL:
useUrlbox\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'] =1280;$options['height'] =1024;// Create the Urlbox URL$urlboxUrl=$urlbox->generateUrl($options);// $urlboxUrl is now 'https://api.urlbox.io/v1/API_KEY/TOKEN/png?url=example.com'// Generate a screenshot by loading the Urlbox URL in an img tag:echo'<img src="'.$urlboxUrl.'" alt="Test screenshot generated by Urlbox">'
If you're using Laravel and have setup the service provider, you can use the Facade provided:
useUrlbox\Screenshots\Facades\Urlbox;$options["url"] ="example.com";$urlboxUrl=Urlbox::generateUrl($options);// $urlboxUrl is now 'https://api.urlbox.io/v1/API_KEY/TOKEN/png?url=example.com'
You can now use the result ($urlboxUrl) by placing it inside an <img/> tag as the src parameter.
When you load the image, a screenshot of example.com will be returned.
The following options can be passed to the generateUrl method:
The URL of the website you want to screenshot (Required)
Viewport width of the browser in pixels
Viewport height of the browser in pixels
Take a screenshot of the element that matches this selector
Width in pixels of the generated thumbnail, leave off for full-size screenshot
Image format of the resulting screenshot image (png or jpg)
User-Agent string used to emulate a particular client.
Set a cookie value before taking a screenshot. E.g. OptIn=true. Can be set multiple times to set more than one cookie.
Amount of time to wait in milliseconds before urlbox takes the screenshot
Waits for the element specified by this selector to be visible on the page before taking a screenshot
Amount of time to wait in milliseconds for the website at url to respond
Specify whether to capture the full-length of the website
Enable the flash plugin for flash using websites
Take a fresh screenshot instead of getting a cached version
2592000 (30 days)
Short for 'time to live'. Number of seconds to keep a screenshot in the cache. Note the default is also the maximum value for this option.
JPEG only - image quality of resulting screenshot (0-100)
Take a 'retina' or high definition screenshot equivalent to setting a device pixel ratio of 2.0 or @2x. Please note that retina screenshots will be double the normal dimensions and will normally take slightly longer to process due to the much bigger image size.
Element selector that is clicked before taking a screenshot e.g. #clickme would click the element with id="clickme"
Element selector that is hovered before taking a screenshot e.g. #hoverme would hover over the element with id="hoverme"
Hex code or css color string. Some websites don't set a body background colour, and will show up as transparent backgrounds with PNG or black when using JPG. Use this setting to set a background colour. If the website explicitly sets a transparent background on the html or body elements, this setting will be overridden.
Crop the width of the screenshot to this size in pixels
Hides all elements that match the element selector by setting their style to display:none !important;. Useful for hiding popups.
Word to highlight on the page before capturing a screenshot
Text color of the highlighted word
Background color of the highlighted word
Save the screenshot directly to the S3 bucket configured on your account