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.4.tar.gz (97.2 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.4-cp310-abi3-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

html2pix-0.6.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.0 MB view details)

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

html2pix-0.6.4-cp310-abi3-macosx_11_0_arm64.whl (5.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

html2pix-0.6.4-cp310-abi3-macosx_10_12_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: html2pix-0.6.4.tar.gz
  • Upload date:
  • Size: 97.2 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.4.tar.gz
Algorithm Hash digest
SHA256 fdf319bb4413a351019fb85f1c1ccae421286416dc3b5964ac4296cb47bfad39
MD5 95185b3a0756a7ca5383e5e2b4e8455a
BLAKE2b-256 b930ba6fc6f8ffcbbe57e6a21e8d1809c453fcbad50d7f77b0de8f5875f764e1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: html2pix-0.6.4-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.6 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.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3bd196fa8c0e952a1516f14ea3f8b4506b84fcc396f5ccea7c6e02a826170720
MD5 8b37c58f915027cecf8f91e1671cdbdb
BLAKE2b-256 fb19a0bb4f9f0a856dfc1f5225f2b126b2884b4d9489f8e32c885c4977f42ba6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for html2pix-0.6.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3df320150d983c63444c8445100729d690c98a300b33fcf4fa30a272c58f3b6c
MD5 b119bcb95b3fdc1c2e5542d5ba3017fc
BLAKE2b-256 397326867cab3283cb6107ea6076aa2aa2f7ed5255a0a448f2870f93062d67fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for html2pix-0.6.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ccffdf1ea2b25223ecc398637339b0ee5aa468047453af664fb178ed317eeb6
MD5 2eed3038fa7737c3f5caccf67c28df61
BLAKE2b-256 beadf9201d605de6ebfa278496af5566d73a4601d50b33378ce3863c466c42fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for html2pix-0.6.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d854d01be9050cddeb0d4e54fa2fae4a19d5ee8d68710f75a431be4078728447
MD5 6c3c0b3774424cf852f78cc23ea5487a
BLAKE2b-256 b2da3e74a4b80e152ec92c908d26869b444a3c112f93ab6422fdb8261a0b452f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.6

5 files

0.6.5

5 files

This release

0.6.4 This release

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