File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace Vormkracht10 \LaravelOpenGraphImage ;
44
5+ use Illuminate \Support \Facades \Storage ;
6+ use Illuminate \Support \Facades \View ;
57use Illuminate \View \ComponentAttributeBag ;
8+ use Vormkracht10 \LaravelOpenGraphImage \Http \Controllers \LaravelOpenGraphImageController ;
69
710class 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}
Original file line number Diff line number Diff line change 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+ });
You can’t perform that action at this time.
0 commit comments