Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Og Image Laravel Package

spatie/laravel-og-image

Generate Open Graph images in Laravel from Blade-defined HTML. Automatically renders screenshots, serves them from a route, and caches files. Templates reuse your app’s CSS, fonts, and Vite assets—no external API required.

View on GitHub
Deep Wiki
Context7

title: Customizing actions weight: 6

The package uses action classes for its core operations. You can replace any of them with your own implementation to customize the behavior. Each action has small, focused protected methods that you can override individually.

Available actions

The following actions are registered in the og-image config file:

'actions' => [
    'generate_og_image' => \Spatie\OgImage\Actions\GenerateOgImageAction::class,
    'inject_og_image_fallback' => \Spatie\OgImage\Actions\InjectOgImageFallbackAction::class,
    'render_og_image_screenshot' => \Spatie\OgImage\Actions\RenderOgImageScreenshotAction::class,
],

GenerateOgImageAction

Handles the full flow when a social platform requests an OG image URL (/og-image/{hash}.jpeg): checking if the image exists on disk, looking up the page URL, taking a screenshot with locking, and serving the image directly.

Overridable methods: serveImage, generateImage, respondWithImage, redirectToImage.

InjectOgImageFallbackAction

Handles injecting fallback OG image meta tags and template content into pages that don't have an <x-og-image> component.

Overridable methods: renderFallback, injectBeforeClosingTag.

RenderOgImageScreenshotAction

Handles rendering the screenshot page when ?ogimage is appended to a URL. Extracts the template content and head from the page, and renders the screenshot view.

Overridable methods: extractHead.

Overriding an action

Create a class that extends the default action and override the methods you want to customize:

namespace App\Actions;

use Spatie\OgImage\Actions\GenerateOgImageAction;

class CustomGenerateOgImageAction extends GenerateOgImageAction
{
    protected function generateImage(array $cached, string $path, $disk): void
    {
        // Custom generation logic...
    }
}

Then register it in config/og-image.php:

'actions' => [
    'generate_og_image' => \App\Actions\CustomGenerateOgImageAction::class,
],
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport