Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use wkhtmltoimage from PHP by installing the binary, confirming PHP can execute it, then calling it through a wrapper such as KnpLabs Snappy. Snappy handles common process plumbing while letting you set image options and save or return the result. The key caveat is that wkhtmltoimage uses the legacy Qt WebKit engine, so test the pages you need to render and isolate the process, especially when HTML or URLs come from users.

What wkhtmltoimage does—and what PHP does

wkhtmltoimage is a command-line program in the wkhtmltopdf project. It renders a URL or local HTML file into an image, using the Qt WebKit rendering engine. PHP does not render the page itself: your PHP application launches the binary, supplies its input and options, then reads or stores the output.

The basic command shape is wkhtmltoimage [OPTIONS]... <input file> <output file>. A URL can be the input, and the output file extension normally selects the image format. Available formats and switches depend on the installed binary, so check its own --extended-help output before relying on an option.

This is a compatibility-bound renderer, not a modern browser automation engine. Modern JavaScript APIs or newer web layout behavior may not work as expected. If fidelity matters, keep representative pages and compare their output whenever you change the binary, operating-system image, or fonts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Install and verify the binary

  1. Install a wkhtmltopdf distribution that includes wkhtmltoimage, or build the project from source. The upstream project documentation links to binaries and source builds.
  2. As the account that will run the renderer, check the executable and version:
    which wkhtmltoimage
    wkhtmltoimage --version
    wkhtmltoimage --extended-help
  3. On Linux, install the shared libraries and fonts required by the selected binary. On Windows, ensure the wkhtmltox DLL is available through PATH.
  4. If running the native binary is difficult on your host, the KnpLabs Snappy packaging project documents bundled binaries and a Docker fallback. Pin and test the image tag, architecture, libraries, and fonts for your deployment rather than assuming one image works everywhere.

First test the renderer outside PHP. This separates an installation problem from a PHP configuration problem:

wkhtmltoimage --format png --width 1280 https://example.com /tmp/example.png

If this command fails when run as the PHP-FPM or worker account, fix that environment before debugging your PHP code.

Generate an image in PHP with KnpLabs Snappy

Snappy provides a PHP object around the executable. Install it from your application directory:

composer require knplabs/knp-snappy

Then set the binary path and options explicitly. The following example renders a URL to a PNG and an HTML string to a separate PNG:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
<?php

require __DIR__ . '/vendor/autoload.php';

use KnpSnappyImage;

$image = new Image('/usr/local/bin/wkhtmltoimage');
$image->setOptions([
    'format' => 'png',
    'width' => 1280,
    'javascript-delay' => 300,
]);

$outputDirectory = __DIR__ . '/var';
if (!is_dir($outputDirectory) && !mkdir($outputDirectory, 0775, true) && !is_dir($outputDirectory)) {
    throw new RuntimeException('Could not create output directory');
}

$image->generate('https://example.com', $outputDirectory . '/example.png');

$html = '<!doctype html><html><body><h1>Invoice</h1></body></html>';
$image->generateFromHtml($html, $outputDirectory . '/invoice.png');

The output directory must exist or be creatable and writable by the PHP process. In a web application, avoid placing generated files in a publicly accessible directory unless that is intentional; alternatively, obtain the generated bytes and return them through your framework’s response handling.

Snappy also supports setting a binary with setBinary(), setting individual options, and returning output for an HTML string. A wrapper helps centralize options and temporary-file handling, but it does not validate untrusted input or make an unsafe renderer safe.

Use the Symfony bundle when the app is already on Symfony

The bundle registers an image service and lets you configure its executable separately from the PDF binary. Install it with Composer:

composer require knplabs/knp-snappy-bundle

For example, configure the image service in config/packages/knp_snappy.yaml:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
knp_snappy:
  image:
    enabled: true
    binary: /usr/local/bin/wkhtmltoimage
    options:
      format: png
      width: 1280
  process_timeout: 20

A controller can render a Twig view to HTML and return the image bytes. Ensure the response type matches the configured format; this example uses a JPEG response, so change the image format option to jpeg if using this response class.

public function card(KnpSnappyImage $knpSnappyImage): Response
{
    $html = $this->renderView('card.html.twig', ['name' => 'Ada']);

    return new Response(
        $knpSnappyImage->getOutputFromHtml($html),
        200,
        ['Content-Type' => 'image/png']
    );
}

Use direct process invocation only for a small integration where you are prepared to manage escaping, timeouts, temporary files, and errors yourself. A wrapper or framework bundle reduces that plumbing; neither removes the need for input validation and process isolation.

Choose rendering options deliberately

Option availability can differ between builds and releases. Confirm each option with wkhtmltoimage --extended-help on the actual host, and test the image output rather than assuming a setting is honored.

Need Relevant controls Practical note
Set output geometry --width, --height Width and height control the rendered image dimensions; use a representative page to check cropping and scaling.
Capture a region --crop-x, --crop-y, --crop-w, --crop-h Set crop position and size when a full page is not needed.
Choose format and compression --format, --quality For example, set format to jpeg and quality to 88; verify that the output extension and response MIME type agree.
Wait for client-rendered content JavaScript enable/disable and --javascript-delay A delay can help charts or widgets appear, but it adds time and cannot make unsupported browser APIs work.
Render authenticated pages Cookies and custom headers Pass only the credentials required for the target page; do not log tokens, cookies, or authorization headers.
Control network routing Proxy settings Check that the worker can reach the target through the configured proxy.
Handle load failures Load-error handling Choose whether a failed resource should stop the job or be ignored; ignoring errors can produce incomplete images.

For a Snappy configuration, these options can be set together:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
$image->setOptions([
    'format' => 'jpeg',
    'quality' => 88,
    'width' => 1200,
    'javascript-delay' => 500,
    'load-error-handling' => 'ignore',
]);

For pages you control, a deterministic render-complete signal such as window.status can be preferable to guessing with a long delay. For pages you do not control, use a bounded delay and set a process timeout so slow or stalled pages do not occupy workers indefinitely.

Render local HTML and assets without opening the filesystem

Local HTML may refer to local CSS, images, or fonts. wkhtmltoimage restricts local-file access by default in relevant builds; only enable it when required, and scope access to the smallest directory needed:

wkhtmltoimage --enable-local-file-access 
  --allow /var/www/app/public 
  /var/www/app/public/card.html 
  /tmp/card.png

Use absolute, readable paths for the HTML and assets. Do not enable access broadly just to fix missing assets. If the HTML or its JavaScript is untrusted, local-file access can expose files or contribute to remote code execution risk. Sanitize user-controlled markup, never accept arbitrary input paths, and render under a low-privilege identity with filesystem and network restrictions where practical.

Troubleshoot common PHP and server failures

  • Executable not found: Set the absolute binary path in Snappy or the Symfony bundle. Run which wkhtmltoimage as the same user as PHP-FPM or the worker; a shell’s PATH may differ from the service environment.
  • Exit code 126 or permission denied: Make the file executable and confirm its filesystem mount permits execution. Check parent-directory permissions as well as the binary’s mode.
  • Missing fonts, blank output, or different text layout: Install the fonts and shared libraries expected by the binary. Compare the CLI render under the service account, not only under your login account.
  • Local CSS or images are missing: Check that local access is actually needed, then use --enable-local-file-access with the narrowest --allow directory. Confirm assets are readable and referenced with correct absolute paths.
  • JavaScript content is absent: Confirm JavaScript is enabled, add a bounded delay, and check whether the page relies on modern JavaScript features unsupported by the older Qt WebKit engine. If you control the page, expose a reliable completion signal.
  • The PHP request hangs: Configure a process timeout, limit page and resource work, and move expensive captures to a queue instead of blocking a normal web request. A browser timeout alone may not stop a child process unless the wrapper or worker terminates it.
  • Output format and HTTP response disagree: Align the configured format, filename extension, and response Content-Type. A JPEG response header does not convert a PNG file.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Plan for security, performance, and maintenance

Security boundary

Treat rendering as execution of a potentially hostile workload. A URL can point to internal services, and local HTML can attempt to read files if local access is enabled. Validate allowed URL schemes and destinations, do not accept arbitrary filesystem paths, avoid forwarding secrets to untrusted pages, run the renderer with minimal privileges, and consider AppArmor, SELinux, or container isolation. Keep local-file access off unless needed; when needed, restrict it with a dedicated directory and the smallest practical allow list.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Performance and reliability

Each render launches work outside PHP and may need to fetch a page, load resources, execute JavaScript, and wait before writing an image. Bound process duration and input size, and queue high-cost jobs. Reuse stable HTML and local assets where possible. A longer JavaScript delay may improve completeness for some pages but directly increases render time; it is not a universal fix for incomplete output.

Version and deployment control

The upstream wkhtmltopdf repository is archived and read-only, so treat wkhtmltoimage as a legacy compatibility dependency. Pin the binary and operating-system image, record installed fonts, and keep a visual regression sample. Snappy v1.7.3 was listed on Packagist with a release date of 2026-07-29 and a PHP requirement of >=8.1; confirm the package constraints for the version you install rather than assuming every release has the same requirements.

Or skip the browser setup

If you need a screenshot API rather than a locally installed legacy renderer, ScreenshotNeo takes a URL in one GET request and returns PNG, JPEG, WebP, or PDF. For a PHP caller, use cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with response headers identifying page verdict and billing status. An MCP server provides screenshot and PDF tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up free for ScreenshotNeo—1,000 screenshots a month, no card required.

Frequently Asked Questions

Can I use wkhtmltoimage to create a JPEG instead of a PNG?

Yes. Set the output format to JPEG and use a matching filename extension and HTTP content type. Confirm the installed binary supports the format with its extended help.

Does wkhtmltoimage require a display server on Linux?

No. It is designed to run headlessly, although the selected binary still needs its required shared libraries and fonts.

Is wkhtmltoimage suitable for pages that depend on modern JavaScript?

Not reliably. Its Qt WebKit engine is legacy; test the specific page because a delay cannot compensate for browser APIs the engine does not support.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.