imgkit is a Python 2 and 3 wrapper for the `wkhtmltoimage` utility, which converts HTML content into various image formats (JPG, PNG, etc.) using the Webkit rendering engine and Qt. The library currently stands at version 1.2.3 and is actively maintained, though releases occur on an irregular cadence, with the last major update in February 2023.
pip install imgkitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to convert HTML from a URL, a local file, or a direct string into an image using `imgkit`. It also includes an example of how to configure the path to the `wkhtmltoimage` executable, which is a common requirement for the library to function correctly.
Install `wkhtmltopdf` for your operating system. On Linux/macOS, ensure the `wkhtmltoimage` binary is in your `$PATH`. On Windows, ensure `wkhtmltoimage.exe` (including the `.exe` extension) is in your PATH or explicitly set via `imgkit.config(wkhtmltoimage='C:\path\to\wkhtmltoimage.exe')`.
Instead of `apt-get install wkhtmltopdf`, download and install the static binary from the official wkhtmltopdf site (`https://wkhtmltopdf.org/downloads.html`) or use a script that fetches a full-featured version.
Install `xvfb` (e.g., `sudo apt-get install xvfb` on Debian/Ubuntu) and ensure `xvfb-run` is in your system's PATH or explicitly configured in imgkit.
Check the input HTML for errors. Run `wkhtmltoimage` directly from the command line with your input to see its specific error messages. Increase verbosity if possible or check system logs.
First, install `wkhtmltoimage` on your system (e.g., `sudo apt-get install wkhtmltopdf` on Debian/Ubuntu, download from `wkhtmltopdf.org` for Windows/macOS). If it's not in your system's PATH, specify the full path to the `wkhtmltoimage` executable when creating the `imgkit.Config` object: `config = imgkit.Config(wkhtmltoimage='C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe')` (Windows example) or `config = imgkit.Config(wkhtmltoimage='/usr/local/bin/wkhtmltoimage')` (Linux example), then pass this config to `imgkit.from_...`: `imgkit.from_string(html_content, 'output.jpg', config=config)`.
Install the `imgkit` package using pip: `pip install imgkit`.
Ensure the specified output path is valid and that your Python script has write permissions to that location. Also, check the input HTML/URL for correctness; try with a simpler input first. If running on a server without a graphical display, ensure `xvfb` is installed and configured, or pass appropriate `wkhtmltoimage` options (like `--no-xvfb` if truly not needed or a display server is available).
Install `xvfb` on your system (e.g., `sudo apt-get install xvfb` on Debian/Ubuntu). Ensure `xvfb-run` is in your system's PATH or specify its full path in the `imgkit.Config`: `config = imgkit.Config(wkhtmltoimage='/path/to/wkhtmltoimage', xvfb='/usr/bin/xvfb-run')`.