I'm using PHP-PhantomJS to screenshot an array of URLs. I can't seem to figure out how to get away with not hardcoding the height of the screenshot being taken.
I'd love to set a width and have the height of each page be auto-detected accordingly. Since I'm working with an array of URLs, each page's height is dynamic.
Has anyone had luck with this? My current version looks like this:
public function takeScreenshots($site, $newDir, $dimensions) {
$urlHost = parse_url($site)["host"];
$urlPath = isset(parse_url($site)['path']) ? parse_url($site)['path'] : '';
$urlPathName = str_replace("/", "",$urlPath);
$filepath = $newDir . $urlHost . "_" . $urlPathName . ".jpg";
$client = Client::getInstance();
$client->getEngine()->setPath(base_path().'/bin/phantomjs');
$width = $dimensions["width"];
$height = $dimensions["height"];
$top = 0;
$left = 0;
$request = $client->getMessageFactory()->createCaptureRequest($site, 'GET');
$request->setOutputFile($filepath);
$request->setViewportSize($width, $height);
$request->setCaptureDimensions($width, $height, $top, $left);
$response = $client->getMessageFactory()->createResponse();
$client->send($request, $response);
}