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: Pre-generating images weight: 6

By default, OG images are generated lazily, on the first request from a crawler. This means the first crawler to request the image triggers a Chrome screenshot, which takes a few seconds. If many new pages go live at the same time, this can lead to multiple concurrent screenshot processes and put load on your server.

To avoid this, you can pre-generate images ahead of time.

Using the artisan command

php artisan og-image:generate https://yourapp.com/page1 https://yourapp.com/page2

Using generateForUrl()

You can generate an OG image programmatically by passing a page URL:

use Spatie\OgImage\Facades\OgImage;

$imageUrl = OgImage::generateForUrl('https://yourapp.com/blog/my-post');

This fetches the page, extracts the <x-og-image> template, takes a screenshot, and saves it to disk.

Generating after publishing content

A common pattern is to dispatch a queued job after saving content, so the OG image is ready before any crawler requests it:

use Spatie\OgImage\Facades\OgImage;

class PublishPostAction
{
    public function execute(Post $post): void
    {
        // ... publish logic ...

        dispatch(function () use ($post) {
            OgImage::generateForUrl($post->url);
        });
    }
}
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony