Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aniftyco/laravel-og-image
Open Graph Image Generator for Laravel
https://github.com/aniftyco/laravel-og-image
laravel laravel-package og-image opengraph-images opengraphprotocol
Last synced: 17 days ago
JSON representation
Open Graph Image Generator for Laravel
- Host: GitHub
- URL: https://github.com/aniftyco/laravel-og-image
- Owner: aniftyco
- License: mit
- Created: 2024-10-23T06:07:55.000Z (23 days ago)
- Default Branch: master
- Last Pushed: 2024-10-24T02:44:20.000Z (22 days ago)
- Last Synced: 2024-10-24T16:06:48.169Z (22 days ago)
- Topics: laravel, laravel-package, og-image, opengraph-images, opengraphprotocol
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Open Graph Image Generator for Laravel
> [!WARNING]
> This package is not ready for general consumption## Requirements
Requires PHP 8.1+ and a Chrome/Chromium 65+ executable.
## Installation
You can install the package via Composer:
```sh
composer require aniftyco/laravel-og-image:dev-master
```## Usage
There are multiple ways you can utilize this.
### `GET /og-image` Route
This package registers a `GET` route to `/og-image` which accepts a varadic amount of parameters where only `template` is required and special. This tells the image generator what template to use relavent to `resources/views/og-image/`.
Take this example:
```
https://example.com/og-image?template=post&title=You%20Can%20Just%20Do%20Things
```It is telling the generator to use the `post` template and pass the `$title` property set to `You Can Just Do Things`.
### `og_image()` Helper
Using the `og_image()` helper you have more control over what happens with the OG Images generated. This helper accepts a `template` and an array of data to pass to the view.
#### Returning the OG image as a response:
```php
Route::get('/{user}.png', function(User $user) {
return og_image('user', compact('user'));
});
```#### Saving the OG image to a disk:
```php
$image = og_image('user', compact('user'));$image->storeAs('og-images', ['disk' => 's3']);
```### Writing templates with Blade
Your images are generated using Blade templates, using the following example template in `resources/views/og-image/example.blade.php`:
```blade
@vite(['resources/css/app.css'])
{{ $name }}
{{ $text }}
```
Then if you make a request to `/og-image?template=example&name=OG%20Image%20Generator&text=The%20fastest%20way%20to%20create%20open%20graph%20images%20for%20Laravel!` you will get the following image:
![](.github/assets/example.png)
## Contributing
Thank you for considering contributing to the Attachments for Laravel package! You can read the contribution guide [here](CONTRIBUTING.md).
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.