Download the PHP package html2img/html2img-php without Composer

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

html2img — HTML to image API, rendered in real Chrome

html2img PHP client

Packagist Version PHP Version Total Downloads

The official PHP client for the HTML to Image API. Turn HTML and CSS into images, capture screenshots of live URLs, and render named templates, all returning a typed response object.

Every render runs in real Chrome, so flexbox, grid, custom properties, web fonts and inline JavaScript behave exactly as they do in the browser. The package is framework-agnostic and built on Guzzle, so it works in plain PHP and inside any framework. The full API reference lives in the documentation.

What you can build

Browse the full template library, or try the no-signup browser tools to see the output before you write any code.

Requirements

Installation

Quick start

The API returns a JSON envelope containing the CDN URL of the generated image, not the raw bytes, so you can cache and re-serve it from your own infrastructure. New to the API? Start with the getting started guide.

Configuration

The constructor takes the API key plus optional overrides:

Authentication is sent on every request as the X-API-Key header. See the authentication docs for issuing and rotating keys.

Injecting your own Guzzle client

Pass a pre-configured GuzzleHttp\ClientInterface to reuse your own middleware, retry strategy or logging. The SDK still adds the X-API-Key, Accept and Content-Type headers on every request.

Usage

Render HTML

POST /api/html. Send a complete HTML document and get back an image of the rendered result. Inline your CSS in a <style> block, or reference remote stylesheets and web fonts via <link> tags in the document head. See the html parameter docs for the full input.

Capture a screenshot

POST /api/screenshot. Fetch a public URL in a real browser and capture it. Use selector to crop to a single element, and css to hide cookie banners or chat widgets before the capture. See the url parameter docs.

Generate a PDF

Set format to Format::Pdf on either request and the render comes back as an A4 portrait vector PDF instead of a PNG: text stays selectable and searchable, webfonts are embedded and long content paginates automatically. The API ignores width, height, dpi, fullpage and selector in PDF mode, and the response url points at a .pdf file. One credit, the same as an image. See the format parameter docs.

Render a template

POST /api/v1/templates/{slug}. Render one of your named templates from a JSON data payload. The data is validated server-side per template. Browse the templates to find a slug. Templates output PNG only; format is not available on template renders.

Options

Both HtmlRequest and ScreenshotRequest accept the following. Any option left null is omitted from the request, so the server applies its own default. The complete reference is in the parameter docs.

Option Type Notes
css string Extra CSS injected after the page loads.
width int Viewport width in CSS pixels (1 to 5000).
height int Viewport height in CSS pixels (1 to 5000). Ignored when fullpage is true.
fullpage bool Capture the full scroll length instead of the viewport.
dpi int Device pixel ratio, 1 to 4. Use 2 for retina.
webhookUrl string Switch to async delivery (see below).
msDelay int Wait this many milliseconds after load before capturing (1 to 5000).
waitForSelector string Wait until this CSS selector appears before capturing.
format Format Format::Png (default) or Format::Pdf. PDF output is A4 portrait and ignores the sizing options above.

ScreenshotRequest also accepts selector (string) to crop the capture to a single element. HtmlRequest does not, since you control the markup.

Custom fonts are loaded by referencing them with <link> tags in your HTML document head, or by linking a web font from your captured page.

The response

Every method returns a readonly Html2img\Response\RenderResponse:

Asynchronous delivery

Synchronous requests have a 30 second budget. For captures likely to exceed it, pass a webhookUrl. The API responds immediately with status: "processing" and url: null, then POSTs the final image URL to your endpoint once rendering finishes. See the webhook_url docs.

Error handling

Every failure throws an Html2img\Exception\Html2imgException. Catch that single type to handle any error, or catch a specific subclass. No raw Guzzle exception escapes the client.

Exception When
AuthenticationException 401, missing or invalid API key.
InsufficientCreditsException 402, no credits remaining.
NotSubscribedException 403, no active subscription.
NotFoundException 404, for example an unknown template slug.
ValidationException 400 or 422, with details() per field.
RateLimitException 429, rate or quota exceeded.
TimeoutException 504, the synchronous render budget was exceeded.
ServerException 5xx, an unexpected renderer error.
ConnectionException the request never reached a response.
Html2imgException base type for all of the above.

Other languages

Anything that can make an HTTP request works with the API. There are worked guides for Laravel, Ruby on Rails, Python, JavaScript and Node.js, React and Vue.

Development

This package uses ddev for a containerised PHP environment. It is optional, and you can use vanilla PHP or whatever you use for local dev if you prefer.

Links

Website · Documentation · Templates · Tools · Features · Comparisons · Articles · Pricing

Licence

MIT. See LICENSE.


All versions of html2img-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
guzzlehttp/guzzle Version ^7.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/html2img-php contains the following files

Loading the files please wait ...