我正在使用PHP-PhantomJS来截取一组 URL。我似乎无法弄清楚如何不硬编码正在拍摄的屏幕截图的高度。
我很想设置一个宽度并相应地自动检测每个页面的高度。由于我使用的是一组 URL,因此每个页面的高度都是动态的。
有没有人有这个运气?我当前的版本如下所示:
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);
}