How to screenshot a website/URL in PHP

Converting a URL into an image is a useful function made very simple with Cloudmersive.

To begin, we add the Convert API to our library:

"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",

Then simply call convert_web_url_to_screenshot and set the input as our desired URL.

require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\ConvertWebApi(

new GuzzleHttp\Client(),
$input = new \Swagger\Client\Model\ScreenshotRequest(); // \Swagger\Client\Model\ScreenshotRequest | Screenshot request parameters
try {
$result = $apiInstance->convertWebUrlToScreenshot($input);
} catch (Exception $e) {
echo 'Exception when calling ConvertWebApi->convertWebUrlToScreenshot: ', $e->getMessage(), PHP_EOL;

And it’s as simple as that. Your URL is now a PNG file and you’re good to go.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store