diff --git a/src/OpenGraphImage.php b/src/OpenGraphImage.php index 1dec5cb..c142062 100644 --- a/src/OpenGraphImage.php +++ b/src/OpenGraphImage.php @@ -2,7 +2,10 @@ namespace Vormkracht10\LaravelOpenGraphImage; +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\View; use Illuminate\View\ComponentAttributeBag; +use Vormkracht10\LaravelOpenGraphImage\Http\Controllers\LaravelOpenGraphImageController; class OpenGraphImage { @@ -24,4 +27,27 @@ public function url(array|ComponentAttributeBag $parameters): string return url() ->signedRoute('open-graph-image.file', $parameters); } + + public function createImageFromParams(array $params): string + { + $url = $this->url($params); + + $url = parse_url($url); + + parse_str($url['query'], $params); + + $signature = $params['signature']; + + $imageController = new LaravelOpenGraphImageController; + + if (! $imageController->getStorageFileExists($signature)) { + $html = View::make('open-graph-image::template', $params) + ->render(); + + $imageController->saveOpenGraphImage($html, $signature); + } + + return Storage::disk(config('open-graph-image.storage.disk')) + ->get($imageController->getStorageFilePath($signature)); + } } diff --git a/tests/OpenGraphTest.php b/tests/OpenGraphTest.php new file mode 100644 index 0000000..be65066 --- /dev/null +++ b/tests/OpenGraphTest.php @@ -0,0 +1,15 @@ +markTestSkipped('Pest is not configured correctly yet.'); + + $image = OpenGraphImage::createImageFromParams([ + 'title' => 'title', + 'description' => 'description', + ]); + + expect($image)->toBeString(); +});