Skip to content

Commit

Permalink
Create image from params
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Oct 9, 2023
1 parent a67662c commit c188eb2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/OpenGraphImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Vormkracht10\LaravelOpenGraphImage;

use Illuminate\Support\Facades\Storage;
use Illuminate\View\ComponentAttributeBag;
use Vormkracht10\LaravelOpenGraphImage\Http\Controllers\LaravelOpenGraphImageController;
use Illuminate\Support\Facades\View;

class OpenGraphImage
{
Expand All @@ -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));
}
}

0 comments on commit c188eb2

Please sign in to comment.