{"id":4051,"library":"imgkit","title":"imgkit","description":"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.","status":"active","version":"1.2.3","language":"en","source_language":"en","source_url":"https://github.com/jarrekk/imgkit","tags":["image conversion","html to image","wkhtmltopdf","web rendering","screenshot"],"install":[{"cmd":"pip install imgkit","lang":"bash","label":"Install Python package"},{"cmd":"sudo apt-get install wkhtmltopdf","lang":"bash","label":"Install wkhtmltopdf (Debian/Ubuntu - see warnings)"},{"cmd":"brew install --cask wkhtmltopdf","lang":"bash","label":"Install wkhtmltopdf (macOS)"},{"cmd":"Download installer from https://wkhtmltopdf.org/downloads.html","lang":"text","label":"Install wkhtmltopdf (Windows/Other OS)"}],"dependencies":[{"reason":"Core rendering engine for HTML to image conversion. Must be installed separately as a system-level executable.","package":"wkhtmltopdf (includes wkhtmltoimage binary)","optional":false}],"imports":[{"note":"The primary module for all functionalities.","symbol":"imgkit","correct":"import imgkit"},{"note":"Used to explicitly set the path to the wkhtmltoimage binary or other global options.","symbol":"config","correct":"import imgkit\nconfig = imgkit.config(wkhtmltoimage='/path/to/wkhtmltoimage')"}],"quickstart":{"code":"import imgkit\nimport os\n\n# --- Option 1: Convert from a URL ---\n# imgkit.from_url takes a URL and an output filename\nimgkit.from_url('http://google.com', 'google.jpg')\nprint('Converted Google to google.jpg')\n\n# --- Option 2: Convert from an HTML file ---\n# Create a dummy HTML file\nwith open('test.html', 'w') as f:\n    f.write('<h1>Hello from imgkit!</h1><p>This is a test.</p>')\nimgkit.from_file('test.html', 'test_output.png')\nprint('Converted test.html to test_output.png')\n\n# --- Option 3: Convert from an HTML string ---\nhtml_string = '<html><body><h2>Inline HTML</h2><p style=\"color: blue;\">Styled content.</p></body></html>'\nimgkit.from_string(html_string, 'string_output.jpeg')\nprint('Converted HTML string to string_output.jpeg')\n\n# --- Option 4: Configure wkhtmltoimage path (if not in PATH) ---\n# Replace with the actual path to your wkhtmltoimage executable\n# Example for Windows: r'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe'\n# Example for Linux: '/usr/local/bin/wkhtmltoimage'\nWKHTMLTOIMAGE_PATH = os.environ.get('WKHTMLTOIMAGE_BINARY_PATH', '') \n\nif WKHTMLTOIMAGE_PATH:\n    configuration = imgkit.config(wkhtmltoimage=WKHTMLTOIMAGE_PATH)\n    imgkit.from_string('<h1>Configured Path Test</h1>', 'path_config_output.jpg', config=configuration)\n    print('Converted with custom wkhtmltoimage path.')\nelse:\n    print('WKHTMLTOIMAGE_BINARY_PATH environment variable not set. Skipping custom path configuration example.')\n\n# Clean up dummy file\nos.remove('test.html')","lang":"python","description":"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."},"warnings":[{"fix":"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')`.","message":"The most common issue is `IOError: 'No wkhtmltoimage executable found'`. imgkit is a wrapper and requires the external `wkhtmltoimage` binary (part of `wkhtmltopdf`) to be installed on your system and accessible in the system's PATH, or its path explicitly configured.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"On Debian/Ubuntu, the `wkhtmltopdf` package from official repositories often has reduced functionality (e.g., missing QT patches). This can lead to issues with outlines, headers, footers, or TOC.","severity":"gotcha","affected_versions":"All versions on affected OS"},{"fix":"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.","message":"If using the `xvfb` option in imgkit (e.g., for headless environments), you might encounter `IOError: 'No xvfb executable found'`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"A generic `IOError: 'Command Failed'` indicates that `wkhtmltoimage` was invoked but exited with a non-zero status, meaning it couldn't process the input for various reasons (e.g., invalid HTML, resource loading issues, out of memory).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}