Skip to main content

A tool that can convert HTML to an image

Project description

English description follows Japanese.

変換イメージ(Conversion Example)


概要

html2img は、HTMLを画像に変換するための軽量ツールです。指定された HTML スニペットを描画し、スクリーンショットとして保存します。内部では Playwright を使用しており、ブラウザでの忠実な描画結果を取得できます。

特徴

  • HTMLスニペット → PNG画像へ簡単変換
  • Playwright を利用して高精度レンダリング
  • ビューポートサイズのカスタマイズが可能
  • 依存最小、シンプルなAPI設計

インストール方法

pip install html2img
playwright install

⚠️ 注意 2行目の playwright install を忘れると動作しません。

使い方

import html2img

html = '<span style="color:gray;">Hello,</span><br>World!'
html2img(html, "result.png")

# ウインドウサイズ(ビューポート)の指定も可能
html2img(html, "small.png", viewport = (100, 100))

引数

  • html:描画対象の HTML 文字列
  • filename:保存先の画像ファイル名(PNG推奨)
  • viewport(任意):タプル (幅, 高さ) を指定することでレンダリング領域を調整可能

注意点

  • CSSやJavaScriptを含めることも可能ですが、外部リソースへの依存がある場合は動作しないことがあります。

Overview

html2img is a lightweight utility to convert HTML snippets into image files. It renders the given HTML using a real browser engine and captures a screenshot. Internally, it uses Playwright for precise rendering.

Features

  • Simple HTML-to-image conversion
  • High-fidelity rendering via Playwright
  • Optional viewport size configuration
  • Minimal API, easy to integrate

Installation

pip install html2img
playwright install

⚠️ Note You must run playwright install after installing the library to download the necessary browser engines.

Usage

import html2img

html = '<span style="color:gray;">Hello,</span><br>World!'
html2img(html, "result.png")

# You can also specify the window (viewport) size
html2img(html, "small.png", viewport = (100, 100))

Parameters

  • html: The HTML string to render
  • filename: Output file path (PNG recommended)
  • viewport (optional): Tuple (width, height) for controlling the viewport size

Notes

  • Supports inline CSS and JavaScript. External resources may not load depending on the environment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

html2img-0.0.0.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

html2img-0.0.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file html2img-0.0.0.tar.gz.

File metadata

  • Download URL: html2img-0.0.0.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for html2img-0.0.0.tar.gz
Algorithm Hash digest
SHA256 e0df21b5f0ae61067f41df46d28b7c61309f8946d4b18ec65a5f0783a21d3b2c
MD5 7c0bd5f85c1293f145b146ece32ac269
BLAKE2b-256 29cb30a56ab163fb359848cad328db4543fb082b40a1cc91c284942d7c3761cf

See more details on using hashes here.

File details

Details for the file html2img-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: html2img-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.3

File hashes

Hashes for html2img-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56e86cd35a9b7933c2ac11b006475946a91bb89b8c15903766572d854e286d44
MD5 78f56ae24d58e3095323911fe6506504
BLAKE2b-256 0df5cd2e109b8e7325dc9c783e051473b54e1607ffed22691d998a39cb0fed3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page