Download the PHP package vormkracht10/laravel-open-graph-image without Composer

On this page you can find all versions of the php package vormkracht10/laravel-open-graph-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-open-graph-image

Generate Dynamic Open Graph Images in Laravel using Blade Views

GitHub release (latest by date) Tests Packagist PHP Version Support Latest Version on Packagist Total Downloads

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

First install Google Chrome or Chromium, as you need the binary to use it as a headless browser.

On macOS

On Debian/Ubuntu

For Ubuntu 22.04+ (Note: you'll need to update the environment variable of CHROME_PATH to chomium-browser)

For Ubuntu everything below 22.04

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:

Generating all images in advance

An image is generated the first time its URL is requested, which takes a few seconds. That first request often comes from a crawler (Facebook, LinkedIn, WhatsApp…) that doesn't wait that long and shows the link without an image. To prevent that, generate the images of all pages in advance:

This crawls your site, starting at app.url (or the URL you pass), and collects the og:image and twitter:image URLs of its pages that point to this package. For every image that isn't cached yet, it puts a GenerateImage job on the queue, so the command finishes as soon as the crawl is done and your queue workers draw the images. Images that are cached already are skipped, and an image that is still waiting on the queue isn't queued twice (the job is unique per URL).

To generate the images right away in the command itself instead, for example when you don't run a queue worker, pass --sync:

Choose the queue connection and queue of the jobs in your .env (by default your app's default connection and queue):

Using a running Chrome (faster)

By default a new Chrome is launched for every image and closed again afterwards. Starting Chrome is a large part of the time it takes to generate an image, especially on a small server. Instead, you can keep one Chrome running as a service and let the package connect to it, so only a tab is opened and closed per image. Assets like fonts are then also cached between images.

Point the package to the DevTools address of the running Chrome in your .env:

A ws://127.0.0.1:9222/devtools/browser/... URL works too, but that URL changes every time Chrome starts, so the http:// address is easier. When the running Chrome can't be reached, the exception is reported and the package falls back to launching Chrome from chrome.path, so images keep working when the service is down.

Chrome has to be started with --remote-allow-origins=http://127.0.0.1, otherwise it refuses the connection. The chrome.flags from the config only apply when the package launches Chrome itself; for a running Chrome, pass them on its command line.

For example with systemd (/etc/systemd/system/chrome-og-image.service, then systemctl enable --now chrome-og-image):

Or with Supervisor:

[!WARNING] Only bind the DevTools port to 127.0.0.1 and never expose it (or use --remote-allow-origins=*): anyone who can reach it has full control of the browser, and can for example open internal URLs, read local files and run JavaScript.

chrome-headless-shell (from Chrome for Testing, e.g. npx @puppeteer/browsers install chrome-headless-shell@stable) starts faster and uses less memory than the full Chrome, which makes it a good fit both for the service and for CHROME_PATH.

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

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-open-graph-image with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
chrome-php/chrome Version ^1.13
illuminate/contracts Version ^11.0 || ^12.0|| ^13.0
spatie/crawler Version ^8.0
spatie/laravel-package-tools Version ^1.93
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vormkracht10/laravel-open-graph-image contains the following files

Loading the files please wait ...