public function save($targetFile)
{
if ($targetFile == '') {
throw new Exception('targetfile not set');
}
if (!in_array(strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)), ['jpeg', 'jpg', 'png'])) {
throw new Exception('targetfile extension not valid');
}
if ($this->url == '') {
throw new Exception('url not set');
}
if (filter_var($this->url, FILTER_VALIDATE_URL) === false) {
throw new Exception('url is invalid');
}
if (!file_exists($this->binPath)) {
throw new Exception('binary does not exist');
}
$this->takeScreenShot($targetFile);
if (!file_exists($targetFile) || filesize($targetFile) < 1024) {
throw new Exception('could not create screenshot');
}
if ($this->height > 0) {
$imageManager = new ImageManager();
$imageManager->make($targetFile)->crop($this->width, $this->height, 0, 0)->save($targetFile, $this->quality);
}
return true;
}