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 the page URL weight: 3

When the package caches which URL to screenshot for an OG image, it uses the request URL without query parameters by default. This means /posts?page=2 and /posts?page=3 would both resolve to /posts for the screenshot.

For most pages this is the right behavior, since query parameters like pagination don't affect the OG image. But if your OG image content varies based on query parameters, you can customize how the URL is resolved.

Changing the URL resolution

In your AppServiceProvider, register a closure that receives the current request and returns the URL to use:

use Illuminate\Http\Request;
use Spatie\OgImage\Facades\OgImage;

public function boot(): void
{
    OgImage::resolveScreenshotUrlUsing(function (Request $request) {
        return $request->fullUrl();
    });
}

This will include query parameters in the cached URL, so each unique combination of path and query parameters gets its own screenshot.

You can also selectively include only certain query parameters:

OgImage::resolveScreenshotUrlUsing(function (Request $request) {
    $url = $request->url();

    if ($request->has('category')) {
        $url .= '?category=' . $request->query('category');
    }

    return $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.
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