Download the PHP package backstage/laravel-og-image without Composer
On this page you can find all versions of the php package backstage/laravel-og-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download backstage/laravel-og-image
More information about backstage/laravel-og-image
Files in backstage/laravel-og-image
Package laravel-og-image
Short Description Laravel package to generate dynamic Open Graph images
License MIT
Homepage https://github.com/backstagephp/laravel-og-image
Informations about the package laravel-og-image
Generate Dynamic Open Graph Images in Laravel using Blade Views
This Laravel package enables you to dynamically create Open Graph images for your website based on a single Blade template with HTML and CSS. In our example we use the Tailwind CDN. So designing a dynamic Open Graph Image as a developer just got very easy using this package!
Just add the meta tag with our url to the head of your page. The package will then generate the image and add it to the page. You can edit the view template which you can find in the resources folder.
- Requirements
- Installation
- Usage
- Passing extra attributes
- Clearing cached images
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Requirements
- PHP 8.2+
Installation
First install Google Chrome or Chromium, as you need the binary to use it as a headless browser.
On macOS
On Debian/Ubuntu
On Windows
Download and install Google Chrome or Chromium using on of these links.
Note: configure path to Chrome/Chromium
Sometimes it's necessary to point the package to a custom path where the binary is located, this can be set in the config og-image.chrome.path
. The path can be retrieved using:
Install and configure package
You can install the package via composer:
Run the command to install the package:
You should also publish the views, to change the default layout of your Open Graph images:
This is the content of the published config file (published at config/og-image.php
):
Usage
Add the Blade component into the head of your page. Providing the attributes you need in your view file:
If you want to use a different view than the default, add a view
attribute with the path using dot or slash notation:
If you do not want to use a view but HTML directly in your view file, than you can use the slot to add the HTML to:
[!NOTE] If you're using this option, make sure to clear caches before adding or changing the HTML using
php artisan og-image:clear
to see the result in your browser.
If you don't want to use the blade component you can also use the facade or helper method to generate the url to the image.
And add it like this to your Blade file:
When you share the page on any platform, the image will automatically be generated, cached and then shown in your post. The image from the default template will look like this:
This component uses the 'template' blade view by default. You can change this template to your needs. It is even possible to pass more attributes than the default ones. You can find the default template in the resources folder.
Passing extra attributes
Want to add more custom attributes to modify the button text for example? Simply pass them down to the blade component, facade or helper method:
You can now access the variable in your view by using the {{ $button }}
variable.
Generate image without using the blade component
When you need to generate the image without using the blade component, you can use the following method:
This will return the actual image from your configured storage. You can use this method to generate the image in your own controller for example.
Clearing cached images
All generated open graph images are cached by default. If you want to remove the cache, you can use the following command:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Bas van Dinther
- Mark van Eijk
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-og-image with dependencies
chrome-php/chrome Version ^1.13
illuminate/contracts Version ^11.0 || ^12.0
spatie/laravel-package-tools Version ^1.14