Skip to main content

CLI Usage

Commands

convert - Convert Single File

Convert a single HTML file to an image.

html2png convert [OPTIONS] INPUT

Arguments:

  • INPUT - Input source: file path, URL, or - for stdin

Options:

OptionShortDescription
--output-oOutput image path (default: auto-generated)
--size-sViewport size (e.g., "1920x1080", "mobile", "4k")
--width-WViewport width (overrides --size)
--height-HViewport height (overrides --size)
--dpr-dDevice pixel ratio (default: 3.0)
--qualityJPEG quality 0-100 (default: 80)
--zoom-zPage zoom level (e.g., 1.5 = 150%)
--format-fOutput format (png/jpeg)
--browser-bBrowser engine (chromium/firefox/webkit)
--full-pageCapture full page (default: true)
--viewport-onlyCapture viewport only
--wait-for-wCSS selector to wait for
--timeout-tNavigation timeout in ms (default: 60000)
--wait-strategy-wsPage load strategy
--config-cPath to config file
--verbose-vEnable verbose output
--quiet-qSuppress progress output

batch - Batch Convert Multiple Files

Convert multiple HTML files matching a pattern.

html2png batch [OPTIONS]

Options:

OptionShortDescription
--pattern-pGlob pattern for HTML files (default: "*.html")
--output-dir-oOutput directory (default: current)
--parallel-jNumber of parallel workers (1-16)
--dry-run-nShow what would be converted

All other options from convert command are also supported.

init-config - Generate Config File

Create a default configuration file.

html2png init-config [OPTIONS]

Options:

OptionShortDescription
--output-oOutput file path (default: .html2png.toml)

presets - List Size Presets

Show available size presets and their dimensions.

html2png presets

Examples

Basic Conversion

html2png convert page.html -o output.png

Custom Dimensions

# Use preset
html2png convert page.html --size mobile

# Custom width/height
html2png convert page.html --width 1920 --height 1080

# Set DPR
html2png convert page.html --dpr 2.0

Batch Processing

# Convert all HTML files
html2png batch -p "*.html" -o output/

# Use 4 parallel workers
html2png batch -p "cards/*.html" -o output/ -j 4

Different Browsers

# Use Firefox
html2png convert page.html --browser firefox

# Use WebKit
html2png convert page.html --browser webkit

JPEG Format

html2png convert page.html -o output.jpg --format jpeg --quality 90

Timeout Options

html2png convert slow-page.html --timeout 120000