Skip to main content

html2pix

CI PyPI version

Fast HTML to pixel rendering using Rust and Blitz. Generate production slates, video overlays, and presentation graphics from HTML/CSS templates.

✨ Features

  • 🎨 Modern CSS Support: Gradients, flexbox, grid, border-radius, shadows
  • 📝 Professional Templates: Presentation templates (title cards, credits, quotes, chapters)
  • 🎬 Video Slate Generation: Production-ready metadata overlays for videos
  • 🖼️ Image Compositing: Alpha blend HTML over images and video frames
  • 🎯 RGB/RGBA Output: Full transparency support
  • 💅 CSS Styling: Complete CSS customization
  • SIMD-Accelerated: 4x faster compositing using vector instructions
  • 🚀 Native Performance: Built with Rust/PyO3 for speed
  • 🔌 ComfyUI Integration: Optional node for ComfyUI workflows

🚀 Installation

From PyPI

# Standard installation
pip install html2pix

# With ComfyUI support
pip install html2pix[comfyui]

CLI binary

Prebuilt binaries for macOS, Linux (glibc + static musl), and Windows are on the downloads page. Once installed, the CLI updates itself in place:

html2pix --self-update          # install the latest release
html2pix --self-update --check  # only report whether one is available

From Source

Requires:

  • Rust toolchain: Install from rustup.rs
  • Python 3.10+
git clone https://github.com/melMass/html2pix.git
cd html2pix

# Install with uv (recommended - avoids caching issues)
uv pip install maturin
uv run maturin develop --uv --release

# Or with pip
pip install maturin
maturin develop --release

📖 Usage

Python API

Basic HTML Rendering

from html2pix_ext import render_html
from pathlib import Path
import numpy as np

# Render HTML to pixels
html = "<h1>Hello World</h1>"
image = render_html(
    html=html,
    css_override=None,
    width=800,
    height=600,
    bg_color=(255, 255, 255, 255),
    input_image=None,
    output_format="RGBA",
    scale_factor=1.0,        # DPI scaling (1.0=normal, 2.0=retina)
    color_scheme="light",    # "light" or "dark"
    time=0.0,                # Animation time in seconds
    resources=None           # Optional: custom fonts/images
)

# Result is numpy array (batch, height, width, channels)
print(image.shape)  # (1, 600, 800, 4)

Using Custom Fonts

from pathlib import Path

# Load custom font
font_data = Path('fonts/Inter-Bold.woff2').read_bytes()

html = """
<style>
@font-face {
  font-family: 'Inter';
  src: url('Inter-Bold.woff2');
}
h1 { font-family: 'Inter', sans-serif; }
</style>
<h1>Custom Typography!</h1>
"""

image = render_html(
    html=html,
    width=800,
    height=600,
    resources={
        'Inter-Bold.woff2': font_data  # Clean API with Path().read_bytes()
    }
)

Using Templates

from templates import render_template

# Render a title card
html, css = render_template('title_card', {
    'title': 'Neural Dreams',
    'subtitle': 'A journey through artificial imagination',
    'info': 'Production Company',
    'bottom_text': '2024 • Runtime 4:48'
})

# Render to pixels
image = render_html(
    html=html,
    css_override=css,
    width=1920,
    height=1080,
    bg_color=(10, 10, 10, 255),
    input_image=None,
    output_format="RGBA"
)

Available Templates

Professional Design System - All templates follow a minimalist, sophisticated aesthetic:

  1. title_card - Bold, centered title cards for opening sequences
  2. chapter_card - Minimal section markers with timestamps
  3. quote_card - Elegant text presentation with attribution
  4. credits_card - End credits style with role/name pairs
  5. minimal_overlay - Subtle corner text (4-position support)

Video Processing

Simple watermark (3 lines):

from html2pix.video import apply_html_overlay

html = '<div style="position: absolute; top: 20px; left: 20px;">My Watermark</div>'
apply_html_overlay('input.mp4', 'output.mp4', html)

Dynamic per-frame overlays:

from html2pix.video import process_video

def add_frame_counter(frame, frame_num, info):
    html = f'<div>Frame: {frame_num}/{info["total_frames"]}</div>'
    frame_batch = frame[np.newaxis, ...]
    result = render_html(html, width=info['width'], height=info['height'], input_image=frame_batch)
    return result[0]

process_video('input.mp4', 'output.mp4', add_frame_counter)

VFX breakdown slates:

from html2pix import generate_video_slate_html
from html2pix.video import process_video

metadata = {
    'title': 'VFX Shot Breakdown',
    'fps': 25,
    'total_frames': 121,
    'inference_settings': {'model': 'SDXL', 'steps': 50},
    'prompt': 'Cinematic establishing shot...'
}

html, css = generate_video_slate_html(metadata, layout='side-by-side')

def add_slate(frame, frame_num, info):
    # Your slate compositing logic here
    ...

process_video('input.mp4', 'output_with_slate.mp4', add_slate)

See examples/showcase_video.py for complete examples.

ComfyUI Integration

When installed with pip install html2pix[comfyui]:

  1. Copy __init__.py to ComfyUI/custom_nodes/html2pix/
  2. Restart ComfyUI
  3. Find node under mtb/render → HTML Render (Blitz)

🎬 Template Examples

All templates render at 1920x1080 with professional typography and spacing:

Title Card

render_template('title_card', {
    'title': 'Neural\nDreams',
    'subtitle': 'A journey through artificial imagination',
    'info': 'Production Company',
    'bottom_text': '2024 • Runtime 4:48'
})

Quote Card

render_template('quote_card', {
    'context': 'On Creation',
    'quote': 'The machine does not dream, but it learns to paint our dreams.',
    'attribution': '— Unknown Artist, 2024'
})

Credits Card

render_template('credits_card', {
    'title': 'Neural Dreams',
    'credits': [
        {'role': 'Directed by', 'name': 'Mel Massadian'},
        {'role': 'Generated with', 'name': 'Stable Diffusion XL'},
        {'role': 'Rendered by', 'name': 'html2pix'},
    ],
    'closing': 'Thank you for watching'
})

🏗️ Architecture

html2pix/
├── __init__.py                  # Python API + ComfyUI node (optional)
├── templates.py                 # Professional template system
├── slate_compositor.py          # Reference image compositing
├── frame_scaler.py              # Video/image scaling utilities
├── render_full_video.py         # Full video processing
├── extension/                   # Rust rendering engine
│   ├── Cargo.toml               # Dependencies (Blitz, wide for SIMD)
│   └── src/lib.rs               # SIMD-optimized compositor
└── pyproject.toml               # Package configuration

How It Works

  1. HTML/CSS Parsing → Blitz HtmlDocument with style resolution
  2. Layout Engine → Compute flexbox, grid, and positioning
  3. Rendering → Blitz paints to RGBA buffer via CPU renderer
  4. SIMD Compositing → Alpha blend using vectorized operations (4 pixels/instruction)
  5. Batch Processing → Composite HTML over video frames or images
  6. Output → Return as numpy arrays (batch, height, width, channels)

SIMD Acceleration

The compositor uses SIMD (Single Instruction, Multiple Data) for 4x faster alpha blending:

// Traditional: Process 1 pixel at a time
for pixel in pixels {
    out = html * alpha + bg * (1 - alpha)  // 1 pixel per cycle
}

// SIMD: Process 4 pixels with ONE instruction
let pixels_vec = f32x4::new([p1, p2, p3, p4]);
let out = html * alphas + bg * one_minus_alpha;  // 4 pixels per cycle!

Performance:

  • 1920×1080 render: ~65ms (down from ~100-150ms)
  • Uses f32x4 vectors via the wide crate
  • Maps to native CPU instructions (SSE/AVX on x86, NEON on ARM)

🔧 Technical Details

Dependencies

Core:

  • numpy >=1.24.4
  • pillow >=10.4.0

Optional (ComfyUI):

  • torch >=2.0.0

Rust (Bundled in wheels):

  • Blitz (commit 2044d690) - HTML/CSS rendering
  • PyO3 (0.22) - Python bindings
  • anyrender_vello_cpu (0.7) - CPU renderer with multithreading
  • wide (0.7) - Portable SIMD intrinsics

Performance

  • Rendering: SIMD-accelerated, ~65ms for 1920x1080
  • Compositing: 4x faster with f32x4 vector operations
  • Video Processing: Efficient frame-by-frame with progress
  • Build Time: ~6-8 seconds (incremental), ~2 minutes (clean)
  • Tested: Up to 1920x1080 @ 25fps, 121-frame videos

Supported CSS Features

✅ Flexbox & Grid layouts ✅ Gradients (linear, radial) ✅ Border radius & box shadows ✅ Typography (font-size, weight, color, line-height) ✅ Padding, margin, spacing ✅ Colors (hex, rgb, rgba) ✅ Text anti-aliasing & smooth rendering

🚧 Limitations

  • Custom resources must be pre-loaded (no live HTTP/filesystem loading)
  • CPU rendering only (no GPU acceleration yet)
  • No JavaScript support (static HTML/CSS only)
  • Blitz is pre-alpha (some advanced CSS features may be incomplete)

🗺️ Roadmap

  • Multi-platform wheel builds (Linux, macOS, Windows)
  • Professional template system
  • Video slate generation
  • SIMD-accelerated compositing
  • Custom font/image loading (pre-bundle API)
  • Publish to PyPI
  • GPU renderer option
  • Auto-loading resources from filesystem/HTTP
  • More template styles
  • CSS animation support (time parameter ready)

📚 Documentation

🤝 Contributing

Contributions welcome! The package is structured to make ComfyUI integration optional while providing a powerful standalone Python library.

📄 License

MIT License - See LICENSE file

🙏 Credits

  • Blitz by DioxusLabs - Blazing fast HTML/CSS rendering engine
  • wide by Lokathor - Portable SIMD intrinsics for Rust
  • Built with Rust, PyO3, and love for beautiful design

🔗 Links

Download files

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

Source Distribution

html2pix-0.6.6.tar.gz (99.9 kB view details)

Uploaded Source

Built Distributions

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

html2pix-0.6.6-cp310-abi3-win_amd64.whl (6.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

html2pix-0.6.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

html2pix-0.6.6-cp310-abi3-macosx_11_0_arm64.whl (5.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

html2pix-0.6.6-cp310-abi3-macosx_10_12_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file html2pix-0.6.6.tar.gz.

File metadata

  • Download URL: html2pix-0.6.6.tar.gz
  • Upload date:
  • Size: 99.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for html2pix-0.6.6.tar.gz
Algorithm Hash digest
SHA256 2e3b015bd50f92ffceafe30fb9f08b2157973670cbeb172f08001f16db11c9bd
MD5 a8df32674855ae0c9bcae583939afb32
BLAKE2b-256 6d21751e092fadb370bb43062b009bbd31c962bff4032be53540eb0dc999bb19

See more details on using hashes here.

File details

Details for the file html2pix-0.6.6-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: html2pix-0.6.6-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.1 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for html2pix-0.6.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 21147b76ccacf7722547b103201e6f0cc101500012e756ccce35ecdfe6209fb3
MD5 b5bbc9f69a49f258d212fb4fad4f59f6
BLAKE2b-256 0c8f883c0bc05f1573898ebb1307261e442e57d63d8f587ac4cc8d564af759cb

See more details on using hashes here.

File details

Details for the file html2pix-0.6.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for html2pix-0.6.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38813354650e809f4b218bea19c6a8abf799328450c66254d457f01915c22a19
MD5 79d2a850b35820519916bf02511ec5b9
BLAKE2b-256 60bb7b4a43192eff4ae0cdd119fe2544f5dff1abc54df45d1ef93034f363bdae

See more details on using hashes here.

File details

Details for the file html2pix-0.6.6-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for html2pix-0.6.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0699016ee1a63333edddd69069850b8c80774e98ec2f870f93081807bcf78b75
MD5 7909e9f495af8ee2f72ad367e97159c1
BLAKE2b-256 0cc513e9beb77a7becb568b463e35c3a66dbdc7ff2b377143f73cf9335a4bc5a

See more details on using hashes here.

File details

Details for the file html2pix-0.6.6-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for html2pix-0.6.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9e79df5209f3e6a49fba6c7897c6460d5c414d8d570edaf90b6763ce6bea0d43
MD5 fd6e4b2bc292a336ac725347eb939c7e
BLAKE2b-256 081ef9f520de944e95793643e1e017aa41bdbc42386608d03913857eb67ab0ec

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.6 This release

5 files

0.6.5

5 files

0.6.4

5 files

0.6.3

26 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page