Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate image without blade directive #17

Merged
merged 8 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\Support\Facades\View;
use Illuminate\View\ComponentAttributeBag;
use Vormkracht10\LaravelOpenGraphImage\Http\Controllers\LaravelOpenGraphImageController;

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));
}
}
15 changes: 15 additions & 0 deletions tests/OpenGraphTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Vormkracht10\LaravelOpenGraphImage\Facades\OpenGraphImage;

it('can generate an image using params', function () {

$this->markTestSkipped('Pest is not configured correctly yet.');

$image = OpenGraphImage::createImageFromParams([
'title' => 'title',
'description' => 'description',
]);

expect($image)->toBeString();
});