Skip to content

Commit d10cd3b

Browse files
committed
Add takeWebsiteScreenshot() method.
1 parent befc4b3 commit d10cd3b

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/Client.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ private function checkTargetFilename(string $targetFilename): void
155155
throw new \Exception('The target file (' . $targetFilename . ') is not writable!');
156156
}
157157
} else {
158-
if (!is_writable(pathinfo($targetFilename, PATHINFO_DIRNAME))) {
158+
$parentDir = pathinfo($targetFilename, PATHINFO_DIRNAME);
159+
while (!is_dir($parentDir)) {
160+
$parentDir = dirname($parentDir);
161+
}
162+
if (!is_writable($parentDir)) {
159163
throw new \Exception('The target file (' . $targetFilename . ') is not writable!');
160164
}
161165
}
@@ -478,4 +482,28 @@ public function convertHTMLFileToPDF(string $sourceFilename, string $targetFilen
478482
$response = $this->sendRequest('/v0/html-file-to-pdf', ['file' => $fileID]);
479483
$this->downloadFile($response['result']['file'], $targetFilename);
480484
}
485+
486+
487+
/**
488+
*
489+
* @param string $url
490+
* @param integer $width
491+
* @param string|integer $height
492+
* @param float $scale
493+
* @param string $format
494+
* @param string $targetFilename
495+
* @return void
496+
*/
497+
public function takeWebsiteScreenshot(string $url, int $width, string|int $height, float $scale, string $format, string $targetFilename): void
498+
{
499+
$this->checkTargetFilename($targetFilename);
500+
$response = $this->sendRequest('/v0/website-screenshot', [
501+
'url' => $url,
502+
'width' => $width,
503+
'height' => $height,
504+
'scale' => $scale,
505+
'format' => $format
506+
]);
507+
$this->downloadFile($response['result']['file'], $targetFilename);
508+
}
481509
}

0 commit comments

Comments
 (0)