Download the PHP package html2img/statamic-og-images without Composer

On this page you can find all versions of the php package html2img/statamic-og-images. 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 statamic-og-images

html2img — HTML to image API, rendered in real Chrome

Open Graph Images for Statamic

Statamic 6 Packagist Version

⚠️ A free html2img API key is required. This addon generates your Open Graph images through the HTML to Image API, so it needs a key to render anything. Creating an account is free and includes 50 credits, no card needed to get started. Images rendered on the free tier are hosted for 7 days; on any paid plan they are hosted permanently, including everything you already rendered before upgrading.

→ Get your free API key at app.html2img.com

Automatic Open Graph (social share) images for your Statamic entries, rendered by the HTML to Image API in real Chrome. You design the card as an ordinary Statamic view with full CSS control, and the addon renders it against each entry, sends the HTML to the API, and stores the returned PNG URL on the entry.

Because the design is a view in your project, not a fixed template, flexbox, grid, custom properties, web fonts and anything else you can write in CSS behave exactly as they do in the browser. Built on the core html2img PHP SDK.

What it does

Requirements

Installation

Add your API key to .env. This is the canonical source:

Publish the config and the default template if you want to customise them:

Open Tools > Open Graph Images in the Control Panel to choose which collections are enabled and set the defaults. See the authentication docs for issuing and rotating keys.

Developer setup

The template

The Open Graph card is a normal Statamic view. The bundled default lives at og-images::default; publish it to resources/views/vendor/og-images/default.antlers.html and edit it, or point the default_template setting at a view of your own, for example og_image.

Templates receive the entry's augmented data, so you reference fields the normal way: {{ title }}, {{ date format="j M Y" }}, your own fields, and globals. The addon also passes:

Treat author, date and an image as optional so one template suits both a blog post and a plain page:

Note that author is a reserved Statamic field (the entry's author user), so name your own byline field something like author_name.

The preview loop

Design in the browser. The addon ships a preview route that renders your template at the exact configured dimensions, with no API key required, since the browser renders the same HTML the API does.

Once the design looks right, the Generate button on the publish screen runs a real render through the API and shows the actual PNG, the parity check between the browser preview and the rendered image.

Local development and public URLs

Renders happen on the HTML to Image servers in real Chrome, so every URL in your template, web fonts, images and stylesheets, must be reachable from the public internet. In production your asset and font URLs already are, so the rendered image matches the browser preview.

On a local development site this is not the case: a locally hosted image, such as an uploaded Statamic asset on *.ddev.site or *.test, is invisible to the API and shows as missing in the rendered PNG, even though your browser preview shows it. The remedy is to reference publicly hosted assets, or to expose your dev site with a tunnel (for example cloudflared tunnel --url ... or ddev share) and point APP_URL at the tunnel while you test. Web fonts loaded from a public CDN, such as Google Fonts, always work because they are already public.

Configuration

config/statamic-og-images.php:

Key Default Purpose
api_key env('HTML2IMG_API_KEY') The API key. The environment is canonical.
default_template og-images::default The view rendered into the image.
width / height 1200 / 630 Image dimensions in CSS pixels.
dpi 2 Device pixel ratio, 1 to 4.
collections [] Collections the addon is enabled for.
overrides [] Per-collection template or dimension overrides.
storage cdn cdn or asset (see below).
integration standalone standalone or seo-addon (see below).

The settings can also be managed from the Control Panel. The API key entered there is stored outside version control, in resources/addons/; the environment variable remains the canonical source.

Output modes

Standalone

Emit the tags yourself with the Antlers tag, typically in your <head>:

This outputs og:image, og:image:width, og:image:height, og:image:alt, og:image:type, twitter:card and twitter:image, resolving the cascade (entry custom image, then generated image, then the site fallback). {{ og_image }} on its own returns just the resolved URL.

SEO addon integration

If you already run an SEO addon, set integration to seo-addon and seo_field to the field your addon reads for its social image. The addon writes the generated URL into that field and stays out of the meta business, so SEO Pro or Advanced SEO output it as usual.

Storage modes

Bulk regeneration

After changing a template, regenerate across enabled collections:

--force ignores the input hash and re-renders every entry.

Asynchronous rendering

Synchronous renders have a 30 second budget. The generation job already runs off the request cycle, so this rarely matters, but for very large captures the API also supports webhook delivery.

Other official packages

The same API has official packages for other languages and platforms, all available now:

There are also worked guides for React and Vue, and anything that can make an HTTP request works with the API. Every integration is listed on the integrations hub.

Development

This addon is developed inside a Statamic project using ddev.

Links

HTML to Image API · Screenshot API · HTML to PDF API · Documentation · Statamic guide · Laravel guide · Templates · Pricing · PHP SDK

Licence

MIT. See LICENSE.


All versions of statamic-og-images with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
html2img/html2img-php Version ^1.0.1
statamic/cms Version ^6.0
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 html2img/statamic-og-images contains the following files

Loading the files please wait ...