Skip to content

Fix createImageFromParams to return raw image or url using a custom template #34

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

Merged
merged 3 commits into from
Jun 14, 2025
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ sudo xattr -rd com.apple.quarantine /Applications/Chromium.app # Remove quaranti

### On Debian/Ubuntu

For Ubuntu 22.04+ (Note: you'll need to update the environment variable of `CHROME_PATH` to `chomium-browser`)

```bash
sudo add-apt-repository ppa:savoury1/ffmpeg4
sudo add-apt-repository ppa:savoury1/chromium
sudo apt-get update
sudo apt-get install chromium-browser
```

For Ubuntu everything below 22.04

```bash
# Install chromium from PPA instead of snap, because of permission issues with snapd version
sudo add-apt-repository ppa:saiarcot895/chromium-dev -y
Expand Down
28 changes: 20 additions & 8 deletions src/OgImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getStorageImageFilePath(string $signature): string

public function getStorageImageFileExists(string $signature): bool
{
if(config('og-image.debug') === true) {
if (config('og-image.debug') === true) {
return false;
}

Expand All @@ -69,7 +69,9 @@ public function getStorageImageFileData(string $signature): ?string
{
return $this->getStorageDisk()
->get($this->getStorageImageFilePath($signature));
} public function getStorageViewFileName(string $signature): string
}

public function getStorageViewFileName(string $signature): string
{
return $signature.'.blade.php';
}
Expand Down Expand Up @@ -132,19 +134,29 @@ public function getSignature(array|ComponentAttributeBag $parameters): string
return $parameters['signature'];
}

public function createImageFromParams(array $parameters): ?string
public function createImageFromParams(array $parameters, ?string $template = null, bool $returnImage = false): ?string
{
$signature = $this->getSignature($parameters);

if (! OgImage::getStorageImageFileExists($signature)) {
$html = View::make('og-image::template', $parameters)
->render();
if (! empty($template) && View::exists($template)) {
$html = View::make($template, $parameters)
->render();
} else {
$html = View::make('og-image::template', $parameters)
->render();
}

OgImage::saveImage($html, $signature);
}

return Storage::disk(config('og-image.storage.disk'))
->url(OgImage::getStorageImageFilePath($signature));
if (! $returnImage) {
return Storage::disk(config('og-image.storage.disk'))
->url(OgImage::getStorageImageFilePath($signature));
} else {
return Storage::disk(config('og-image.storage.disk'))
->get(OgImage::getStorageImageFilePath($signature));
}
}

public function saveImage(string $html, string $filename): void
Expand Down Expand Up @@ -196,7 +208,7 @@ public function getResponse(Request $request): Response
->render();
}

if($request->route()->getName() == 'og-image.html') {
if ($request->route()->getName() == 'og-image.html') {
return response($html, 200, [
'Content-Type' => 'text/html',
]);
Expand Down
Loading