Download the PHP package html2img/html2img-laravel without Composer

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

html2img — HTML to image API, rendered in real Chrome

html2img for Laravel

Packagist Version PHP Version Laravel Version Total Downloads

The official Laravel integration for the HTML to Image API. Turn HTML and CSS into images, capture screenshots of live URLs, and render named templates, all behind a clean facade with zero-config auto-discovery.

It wraps the framework-agnostic html2img PHP SDK (source) and adds the Laravel pieces you would otherwise write yourself: a service provider, a published config file, a facade, container bindings, an artisan health check, and one-line saving of a render to any filesystem disk.

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 full API reference lives in the documentation, with a Laravel-specific guide at html2img.com/docs/usage/laravel.

Contents

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

The service provider and the Html2img facade are registered automatically through package discovery. Add your API key to .env:

That is the whole setup. See the authentication docs for issuing and rotating keys, and the getting started guide for a tour of the API.

Optionally publish the config file:

Configuration

The published config/html2img.php reads from your environment:

Variable Default Purpose
HTML2IMG_API_KEY none Your key, sent as the X-API-Key header.
HTML2IMG_BASE_URI https://app.html2img.com API base URI. You rarely need to change this.
HTML2IMG_TIMEOUT 35 Request timeout in seconds.
HTML2IMG_DISK default disk Disk used by Html2img::store().

Custom HTTP client

The integration is built on Guzzle. To add your own retry middleware, logging or proxy settings, bind a configured GuzzleHttp\ClientInterface as html2img.http, for example in a service provider:

The package still sends the X-API-Key, Accept and Content-Type headers on every request.

Usage

Reach the API through the Html2img facade. Each method returns a readonly Html2img\Response\RenderResponse. The request objects come from the underlying SDK, so import them from the Html2img\Request namespace.

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.

Rendering a Blade view into the image, as above, keeps your markup where the rest of your app lives.

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 and the selector 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 the built-in templates from a JSON data payload. The data is validated server-side per template. Templates output PNG only; format is not available on template renders.

Saving renders to a disk

The API returns the CDN URL of the image rather than the raw bytes, so you can cache and re-serve it from your own infrastructure. When you would rather keep a copy, store() downloads the image and writes it to any filesystem disk in one line:

You can also pass a URL string directly, or grab the raw bytes without storing them:

Queues and jobs

Renders are a natural fit for a queued job, especially full-page captures that take a few seconds. Resolve the facade or type-hint the manager:

For very large captures, prefer asynchronous delivery over a long-running job.

Render 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 Docs
css string css
width int dimensions (1 to 5000)
height int dimensions (ignored when fullpage)
fullpage bool fullpage
dpi int dpi (1 to 4, use 2 for retina)
webhookUrl string webhook-url
msDelay int ms_delay (1 to 5000)
waitForSelector string wait_for_selector
format Format format: Format::Png (default) or Format::Pdf. PDF output is A4 portrait and ignores the sizing options above.

ScreenshotRequest also accepts selector 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 package.

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.

Verifying your setup

Confirm your key and configuration with the bundled artisan command, which renders a small test image:

It prints the resulting image URL and your remaining credits, or a clear error if the key is missing or rejected. The check uses one credit. There is also a testing guide for the API itself.

Other languages

Not on Laravel? The same API has worked guides for plain PHP, 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 · Laravel guide · Templates · Tools · Features · Comparisons · Articles · Pricing · PHP SDK

Licence

MIT. See LICENSE.


All versions of html2img-laravel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
html2img/html2img-php Version ^1.1
illuminate/contracts Version ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^11.0 || ^12.0 || ^13.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-laravel contains the following files

Loading the files please wait ...