Usage: Initate a POST request with the following parameters as JSON:
{
"url": "http://example.com/", // The url of the page of interest.
"viewport_w": "1280px", // Width of the output (for image output)
"viewport_h": "1024px", // Height of the output (for image output), omit to get everything.
"format": "pdf|jpg|png", // The format of the output
"php_sess_name": "PHPSESSID", // Optional. Include if screenshot is behind authentication.
"php_sess_id": "aBcDeF1234567890", // Optional. Include if screenshot is behind authentication.
"php_sess_domain": "example.com", // Optional. Include if screenshot is behind authentication.
"timer": "200|'callback'", // Optional. int: # of miliseconds to wait. 'callback' wait until #phantom-page-ready element appears on page (max 60s)
"cookies": {"mycookie": "myvalue"}, // Optional. JSON object: key / value store of cookies the server should use.
}
<?php
$post_data = [
'url' => 'https://mysite.com/screenshot/this/page',
'format' => 'pdf',
'viewport_w' => '15in',
'viewport_h' => '22in',
'php_sess_name' => session_name(),
'php_sess_id' => session_id(),
'php_sess_domain' => $_SERVER['SERVER_NAME'],
'timer' => 200,
'cookies' => json_encode(['device_token' => 'abcdef123456'])
];
// Close the session so the session doesn't block Shuttershot from accessing the page.
session_write_close();
// Set up curl for the request.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://shuttershot.zingstudios.com/index.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($post_data),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new \Exception("cURL Error #:" . $err);
} else {
return $response;
}