Weave 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 Og Image Laravel Package

spatie/laravel-og-image

Generate Open Graph images for your Laravel app by defining OG image HTML inline in Blade views. The package screenshots them, serves them via a dedicated route, and caches them on disk, inheriting your existing CSS, fonts, and Vite assets.

View on GitHub
Deep Wiki
Context7

Generate OG images for your Laravel app

Frequently asked questions about Laravel Og Image
How do I install and set up spatie/laravel-og-image in a Laravel app?
Install it with composer require spatie/laravel-og-image, optionally publish its config, and add the x-og-image Blade component to your layout or individual views. The package auto-registers middleware that injects the generated meta tags into HTML responses. You will also need Node.js and a Chrome or Chromium binary available because screenshots run through spatie/laravel-screenshot and Browsershot.
Does spatie/laravel-og-image call an external API to generate images?
No. It is designed to run entirely on your own server and uses spatie/laravel-screenshot, Browsershot, Node.js, and a Chrome or Chromium binary to capture the OG image HTML. That means no third-party image API is required, but it does make a headless browser a production runtime dependency. A Cloudflare Browser Rendering driver is mentioned as an alternative path when local Chromium is not feasible.
Which Laravel versions are supported by spatie/laravel-og-image?
The provided context does not include a full Laravel or PHP version matrix, so check the package's composer.json and Packagist page for the exact constraints before adopting it. It is built for Laravel applications that render Blade views and use Vite assets. Pin an exact version and review the changelog because release tags have had versioning hygiene issues.
How does caching work and where are the generated OG images stored?
Generated images are cached on disk and served through a dedicated route using content-hashed URLs such as /og-image/{md5}.jpeg. The files live on the public disk and are served with cache headers, which is designed to work well behind a CDN. Because filenames are content-hashed, old images are never overwritten and can accumulate, so you need a pruning or lifecycle plan.
Can OG image templates use my existing Tailwind CSS, fonts, and Vite assets?
Yes. The package is Blade-first and its templates inherit your page's existing CSS, fonts, and Vite assets, so you do not need a separate styling pipeline for OG images. This reduces design drift between your actual pages and the generated social cards. It fits best in a Blade plus Vite monolith where server-rendered HTML is the delivery mechanism.
How do I handle pages that do not have a custom OG image template?
The package supports a fallback image for long-tail pages that have no explicit template, which helps avoid blank social cards on archive, tag, or search pages. Define the fallback deliberately and verify it after deployment. Be aware that a past release had a fallback cache-poisoning bug involving non-HTML responses, so test feeds and other non-HTML routes and stay on a patched version.
What infrastructure does spatie/laravel-og-image need in production?
You need a long-lived container or server that can run Node.js and a Chrome or Chromium binary, because headless Chrome is the screenshot engine. Headless Chrome is memory- and CPU-hungry, commonly around 150 to 300 MB per instance, so tightly sized Fargate tasks and Vapor or Lambda environments may not be suitable. If local Chromium is not feasible, the Cloudflare Browser Rendering driver is the alternative path mentioned in the assessment.
Can I generate OG images asynchronously so crawlers never trigger a cold render?
The described flow generates the image synchronously inside the request when a URL is not already cached, which can create a latency spike precisely when a social crawler fetches it. To reduce that risk, warm the cache after publishing, for example with a queued job that requests the OG image URL, and measure your p95 render time against LinkedIn and Slack fetch budgets. The provided context does not document a built-in queue mode for generation.
Is spatie/laravel-og-image safe when OG titles contain user-generated content?
Version 1.3.2 fixed the component compiling user content as Blade, so titles containing Blade syntax such as {{ }} or @each were a template-injection and XSS-adjacent surface. Upgrade to at least 1.3.2 and treat any user-authored parts of the OG template as untrusted content. Escape or sanitize user input and avoid letting users author raw Blade markup.
What are alternatives to spatie/laravel-og-image?
Alternatives include external OG image generation APIs or hosted services, static pre-designed images per page, or a custom Browsershot implementation inside your Laravel app. The main differentiator of this package is that it is self-hosted, Blade-first, and inherits your existing CSS, fonts, and Vite assets. Choose it when you want no external API and can run Chromium in production; choose a hosted service when you cannot.
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.
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table