{"id":5960,"library":"html2image","title":"html2image Library","description":"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.","status":"active","version":"2.0.7","language":"en","source_language":"en","source_url":"https://github.com/vgalin/html2image","tags":["html","css","image","screenshot","browser","headless","conversion"],"install":[{"cmd":"pip install html2image","lang":"bash","label":"Install `html2image`"}],"dependencies":[],"imports":[{"symbol":"Html2Image","correct":"from html2image import Html2Image"}],"quickstart":{"code":"from html2image import Html2Image\nimport os\n\n# Ensure you have a headless browser (Chrome, Chromium, Edge, or Firefox) installed\n# For example, on Ubuntu:\n# sudo apt-get update\n# sudo apt-get install chromium-browser\n\nhti = Html2Image(size=(1920, 1080), browser='chrome')\n\n# Take a screenshot of a website\nhti.screenshot(\n    url='https://www.python.org',\n    save_as='python_org.png',\n    # You can specify a custom executable path if the browser isn't in PATH\n    # executable_path='/usr/bin/chromium-browser'\n)\nprint(\"Screenshot of python.org saved as python_org.png\")\n\n# Take a screenshot of an HTML string\nhtml_content = \"\"\"\n<h1 style=\"color: blue;\">Hello, `html2image`!</h1>\n<p>This is a test of string conversion.</p>\n\"\"\"\nhti.screenshot(html_str=html_content, save_as='hello_html.png')\nprint(\"Screenshot of HTML string saved as hello_html.png\")\n\n# Clean up generated files for demonstration\n# os.remove('python_org.png')\n# os.remove('hello_html.png')","lang":"python","description":"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."},"warnings":[{"fix":"Install a supported browser (e.g., `sudo apt-get install chromium-browser` on Debian/Ubuntu) or set `Html2Image(executable_path='/path/to/browser')`.","message":"The `html2image` library requires a compatible headless web browser (Chrome, Chromium, Edge, or Firefox) to be installed on your system. It does not automatically install one. Ensure your chosen browser is in your system's PATH, or provide its executable path via the `executable_path` parameter during initialization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the `html2image` README and documentation for version 2.0.0+ regarding browser configuration and flags. Use the `browser_args` parameter for custom arguments.","message":"Version 2.0.0 introduced significant internal structural changes and revamped how browser flags are handled. Custom browser configurations or direct manipulation of browser arguments from pre-2.0.0 versions might require updates.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"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.","message":"Starting with version 2.0.5, `html2image` defaults to using Chrome's `--headless=new` flag for improved compatibility with newer browser versions. If you encounter issues with older browser versions or specific environments, you might need to revert to the old headless mode.","severity":"breaking","affected_versions":">=2.0.5"},{"fix":"Update any code setting the background color flag to use '000000' instead of '0'.","message":"Version 2.0.3 fixed an issue where the default background color flag for Chrome/Chromium changed from '0' to '000000'. If you were relying on the '0' value, it might no longer be supported on newer Chromium versions.","severity":"deprecated","affected_versions":"<2.0.3"},{"fix":"Always install `html2image` version 2.0.3 or later to ensure stability and avoid known issues.","message":"Version 2.0.2 was yanked from PyPI shortly after its release due to a problematic wheel file. Avoid installing or using this specific version.","severity":"gotcha","affected_versions":"2.0.2"},{"fix":"Consult the latest `html2image` documentation or run `html2image --help` to understand the updated CLI arguments and options.","message":"Version 2.0.7 introduced a new and improved Command Line Interface (CLI). Existing shell scripts or automation relying on the `html2image` command-line utility might need updates to match the new argument structure and syntax.","severity":"gotcha","affected_versions":">=2.0.7 (for CLI users)"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}