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 screenshots weight: 3

You can customize how OG images are generated by calling methods on the OgImage facade in your AppServiceProvider. All methods are chainable.

Size

By default, images are generated at 1200×630 pixels with a device scale factor of 2, resulting in crisp 2400×1260 pixel images. You can change the global default:

use Spatie\OgImage\Facades\OgImage;

public function boot(): void
{
    OgImage::size(1200, 630);
}

You can also override the size per component:

<x-og-image :width="800" :height="400">
    <div>This OG image will be 800×400</div>
</x-og-image>

Per-component dimensions take priority over the global config. When custom dimensions are used, the content hash includes the dimensions, so the same HTML at different sizes produces different images.

Format

The default format is JPEG. You can change it to PNG or WebP:

OgImage::format('webp');

Quality

You can set the image quality for JPEG and WebP formats in your config:

// config/og-image.php
'quality' => 80,

When set to null (the default), the screenshot driver's default quality is used. You can also set quality via configureScreenshot() for more control.

Disk

By default, images are stored on the public disk in the og-images directory. You can change both:

OgImage::disk('s3', 'og-images');

Chaining

All methods can be chained:

OgImage::format('webp')
    ->size(1200, 630)
    ->disk('s3', 'og-images');

Cloudflare

Instead of using Browsershot (the default), you can use Cloudflare's Browser Rendering to generate screenshots:

OgImage::useCloudflare(
    apiToken: env('CLOUDFLARE_API_TOKEN'),
    accountId: env('CLOUDFLARE_ACCOUNT_ID'),
);

For more details, see installation & setup.

Configuring the screenshot builder

For full control over the screenshot process, use configureScreenshot(). The closure receives the ScreenshotBuilder instance after the URL, size, disk, and driver have been set:

use Spatie\LaravelScreenshot\Enums\WaitUntil;
use Spatie\LaravelScreenshot\ScreenshotBuilder;

OgImage::configureScreenshot(function (ScreenshotBuilder $screenshot) {
    $screenshot->waitUntil(WaitUntil::NetworkIdle0);
});

This can be combined with useCloudflare() or useDriver(). The driver is applied first, then your configureScreenshot callback runs on top:

OgImage::useCloudflare(
        apiToken: env('CLOUDFLARE_API_TOKEN'),
        accountId: env('CLOUDFLARE_ACCOUNT_ID'),
    )
    ->configureScreenshot(function (ScreenshotBuilder $screenshot) {
        $screenshot->waitUntil(WaitUntil::NetworkIdle0);
    });

Common options

deviceScaleFactor

Controls the device pixel ratio. Defaults to 2, producing retina-quality 2400×1260 pixel images at the default 1200×630 viewport. Set to 1 if you prefer smaller file sizes over sharpness.

waitUntil

Determines when the page is considered loaded. Supported values:

  • 'load': wait for the load event
  • 'domcontentloaded': wait for the DOMContentLoaded event
  • 'networkidle0': wait until there are no more than 0 network connections for at least 500ms
  • 'networkidle2': wait until there are no more than 2 network connections for at least 500ms

waitForTimeout

Additional time to wait (in milliseconds) after the page has loaded. Useful if you need to wait for fonts or animations to complete.

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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai