The html2image package provides a Pythonic wrapper around headless web browsers (Chrome, Chromium, Edge, Firefox) to convert URLs, HTML strings, or HTML files (with CSS) into images. It's actively maintained with frequent updates, currently at version 2.0.7, focusing on browser compatibility and feature enhancements.
pip install html2imageVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `Html2Image` and use it to capture screenshots from both a URL and an HTML string. Remember that a compatible headless browser must be installed on your system for `html2image` to function.
Install a supported browser (e.g., `sudo apt-get install chromium-browser` on Debian/Ubuntu) or set `Html2Image(executable_path='/path/to/browser')`.
Review the `html2image` README and documentation for version 2.0.0+ regarding browser configuration and flags. Use the `browser_args` parameter for custom arguments.
For versions 2.0.5 and later, try initializing with `Html2Image(force_old_headless_mode=True)` or `Html2Image(browser_args=['--headless=old'])` if `headless=new` causes problems.
Update any code setting the background color flag to use '000000' instead of '0'.
Always install `html2image` version 2.0.3 or later to ensure stability and avoid known issues.
Consult the latest `html2image` documentation or run `html2image --help` to understand the updated CLI arguments and options.
Install a supported browser (e.g., `sudo apt-get install chromium-browser` on Debian/Ubuntu, or ensure Chrome/Edge is installed on Windows/macOS), or specify the browser's executable path during `Html2Image` initialization: `hti = Html2Image(executable_path='/path/to/browser/executable')`.
For `html2image` versions 2.0.5 and later, try initializing with `Html2Image(force_old_headless_mode=True)` or `Html2Image(browser_args=['--headless=old'])` if using older browser versions that may not fully support the new headless mode, or ensure your browser is up-to-date.
Configure the browser type by passing the `browser` argument in the `Html2Image` constructor: `hti = Html2Image(browser='edge')`. The `browser` attribute itself is an internal object and should not be directly reassigned as a string.
Install the missing shared library. For `libxul.so`, this typically means installing or ensuring Firefox is correctly installed and its dependencies are met (e.g., `sudo apt-get install firefox` or `sudo apt-get install libxul-dev` if available for your distribution).
No dependency data recorded yet.