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.
<x-og-image>) integrates seamlessly with existing views. No manual image generation or external services required.spatie/laravel-screenshot (uses Browsershot/Chromium), which needs Node.js and Chrome/Chromium installed. Compatible with Laravel 9+.og-image:generate Artisan command or queued jobs).Cache-Control headers and don’t cache stale images indefinitely.try_files optimizations to bypass PHP for static images?og-image route.dispatch() in PublishPostAction), decoupling image generation from user requests.<x-og-image>) for explicit OG images.OgImage::fallbackUsing().og-image:generate or generateForUrl().try_files in nginx for local disks.file_get_contents for remote URL generation (e.g., generateForUrl()). Disable if using allow_url_fopen = Off (use cURL instead).spatie/laravel-screenshot settings.@vite directives are processed in OG templates (e.g., <link rel="stylesheet" href="@vite('resources/css/app.css')">).composer require spatie/laravel-og-image spatie/laravel-screenshot
Publish config if needed:
php artisan vendor:publish --tag="og-image-config"
AppServiceProvider:
OgImage::size(1200, 630)->format('webp');
<x-og-image> to views or implement fallbacks.spatie/laravel-og-image and spatie/laravel-screenshot for breaking changes. Test upgrades in staging.spatie/laravel-screenshot config.php artisan og-image:clear or automate via cron jobs (e.g., weekly).storage/app/public/og-images).try_files further optimizes static image delivery.spatie/laravel-screenshot config (e.g., max_processes).memory_limit.| Failure Scenario | Impact | Mitigation |
How can I help you explore Laravel packages today?