Skip to content

Commit 8f5e0ad

Browse files
authored
Generate image without blade directive (#17)
* Create image from params * Fix styling * Add test * Fix styling * Remove test as it's not working at the moment * Mark test skipped --------- Co-authored-by: Baspa <Baspa@users.noreply.github.com>
1 parent a67662c commit 8f5e0ad

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/OpenGraphImage.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace Vormkracht10\LaravelOpenGraphImage;
44

5+
use Illuminate\Support\Facades\Storage;
6+
use Illuminate\Support\Facades\View;
57
use Illuminate\View\ComponentAttributeBag;
8+
use Vormkracht10\LaravelOpenGraphImage\Http\Controllers\LaravelOpenGraphImageController;
69

710
class OpenGraphImage
811
{
@@ -24,4 +27,27 @@ public function url(array|ComponentAttributeBag $parameters): string
2427
return url()
2528
->signedRoute('open-graph-image.file', $parameters);
2629
}
30+
31+
public function createImageFromParams(array $params): string
32+
{
33+
$url = $this->url($params);
34+
35+
$url = parse_url($url);
36+
37+
parse_str($url['query'], $params);
38+
39+
$signature = $params['signature'];
40+
41+
$imageController = new LaravelOpenGraphImageController;
42+
43+
if (! $imageController->getStorageFileExists($signature)) {
44+
$html = View::make('open-graph-image::template', $params)
45+
->render();
46+
47+
$imageController->saveOpenGraphImage($html, $signature);
48+
}
49+
50+
return Storage::disk(config('open-graph-image.storage.disk'))
51+
->get($imageController->getStorageFilePath($signature));
52+
}
2753
}

tests/OpenGraphTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Vormkracht10\LaravelOpenGraphImage\Facades\OpenGraphImage;
4+
5+
it('can generate an image using params', function () {
6+
7+
$this->markTestSkipped('Pest is not configured correctly yet.');
8+
9+
$image = OpenGraphImage::createImageFromParams([
10+
'title' => 'title',
11+
'description' => 'description',
12+
]);
13+
14+
expect($image)->toBeString();
15+
});

0 commit comments

Comments
 (0)