Setup CloudConvert to take webpage screenshots

This commit is contained in:
Jonny Barnes 2023-01-02 09:39:23 +00:00
parent 0d393bd172
commit 45c71bbb47
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
7 changed files with 177 additions and 38 deletions

View file

@ -15,15 +15,14 @@ use GuzzleHttp\Exception\ClientException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Ramsey\Uuid\Uuid;
use Spatie\Browsershot\Browsershot;
use Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot;
class BookmarkService extends Service
{
/**
* Create a new Bookmark.
*
* @param array $request Data from request()->all()
* @param array $request Data from request()->all()
* @param string|null $client
* @return Bookmark
*/
public function create(array $request, ?string $client = null): Bookmark
@ -75,31 +74,6 @@ class BookmarkService extends Service
return $bookmark;
}
/**
* Given a URL, use `browsershot` to save an image of the page.
*
* @param string $url
* @return string The uuid for the screenshot
*
* @throws CouldNotTakeBrowsershot
*
* @codeCoverageIgnore
*/
public function saveScreenshot(string $url): string
{
$browsershot = new Browsershot();
$uuid = Uuid::uuid4();
$browsershot->url($url)
->setIncludePath('$PATH:/usr/local/bin')
->noSandbox()
->windowSize(960, 640)
->save(public_path() . '/assets/img/bookmarks/' . $uuid . '.png');
return $uuid->toString();
}
/**
* Given a URL, attempt to save it to the Internet Archive.
*