html-to-image-page

HTML to image / webpage screenshot: render HTML fragments or full documents into PNG or JPG images, or capture webpage screenshots, suitable for generating share cards, OG images, or report illustrations. Trigger phrases: html to image, webpage screenshot, render HTML to image, HTML to PNG.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "html-to-image-page" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-6fc084f2194d112030610a6278678f38d20f2bf05b5cbdfc31e99724e3006d9a. Verify the upstream source and version against https://skillhub.cn/skills/user_fac53e4e/html-to-image-page before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

HTML to image / webpage screenshot: render HTML fragments or full documents into PNG or JPG images, or capture webpage screenshots, suitable for generating share cards, OG images, or report illustrations. Trigger phrases: html to image, webpage screenshot, render HTML to image, HTML to PNG.

0 Downloads

Introduction source: third_party · user_fac53e4e · 1.0.1 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Audience
Translation pending; see source documentation.
Inputs and outputs
Translation pending; see source documentation.
Software, accounts and paid services
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: html-to-image
description: >-
  HTML 转图片 / 网页截图 / 渲染 HTML 为图片。当用户希望把 HTML 片段或完整 HTML 文档转换为
  PNG 或 JPG 图片、对网页或 HTML 做截图、或基于 HTML 模板生成分享卡片 / OG 图 / 报告配图时使用。
  触发词(短语):html转图片、html to image、网页截图、渲染HTML为图片、HTML转PNG。
agent_created: true

HTML to Image(HTML 转图片)

Overview

将任意 HTML 内容(片段或完整文档)渲染为高质量的 PNG / JPG 图片。底层使用 Playwright 驱动无头 Chromium 完成真实布局与字体渲染,因此支持 CSS、Flex/Grid、Web 字体、内联 SVG 等现代前端特性, 输出结果等效于在浏览器中打开该 HTML 后截图。

所有转换通过 bundled 脚本 scripts/html_to_image.py 完成,无需手写渲染逻辑。

When to Use(触发条件)

在以下意图出现时调用本 Skill,并优先匹配触发短语,避免误触发:

  • 触发词 / 短语:html转图片、html to image、网页截图、渲染HTML为图片、HTML转PNG
  • 典型用户表述:
    • "把这个 HTML 渲染成一张图片"
    • "帮我把这段网页代码截图保存为 PNG"
    • "用 HTML 模板生成一张分享卡片图片"
  • 不适用(不要触发):已有图片的格式转换(PNG↔JPG 请用图片处理工具)、PDF 转图片、 或对在线真实网站做整站抓取(本 Skill 仅接受用户提供的 HTML 文本/文件,不爬取外部站点)。

Parameters(参数定义)

调用 scripts/html_to_image.py 时,参数如下:

参数 CLI 标志 必填 默认值 说明
HTML 内容 --html 二选一必填 — 内联 HTML 字符串(片段或完整文档)。与 --html-file 二选一。
HTML 文件 --html-file 二选一必填 — 本地 .html 文件路径。也可用位置参数直接传路径。
输出路径 --output / -o 必填 — 结果图片保存路径,如 out.png。目录不存在时自动创建。
图片格式 --format / -f 可选 png 取值 png / jpg / jpeg。JPG 自动以白底渲染(无透明通道)。
视口宽度 --width 可选 800 渲染视口宽度(CSS 像素),影响布局断点与换行。
视口高度 --height 可选 自动 初始视口高度。开启 --full-page 时被忽略(按内容高度截取)。
缩放比例 --scale 可选 2.0 设备缩放因子,等效于提高分辨率(2.0 = Retina 清晰度)。建议 1~3。
整页截取 --full-page / --viewport-only 可选 True 默认截取完整可滚动页面;--viewport-only 仅截当前视口。
JPEG 质量 --quality 可选 92 JPEG 压缩质量 1~100(PNG 无损、忽略此项)。数值越高越清晰、文件越大。
高清预设 --hq 可选 False 一键最高清晰度:强制 scale≥3.0 且 quality≥95。等价于最清晰的快捷开关。
目标宽度 --target-width 可选 — 保证输出至少为该像素宽(如 2000);必要时自动提高 --scale,避免小图模糊。
背景色 --bg 可选 — CSS 颜色或 transparent。PNG 设 transparent 输出带 alpha 通道;JPEG 无透明、默认白底、可改其他实色。
稳定等待 --wait 可选 500 字体就绪后再额外等待的毫秒数,用于动画/字体/异步布局稳定。
复用浏览器 --channel 可选 — 复用本机已装浏览器(如 msedge / chrome)代替内置 Chromium,省去约 180MB 下载,适合 C 盘紧张的机器。

提示:中文股票/涨跌配色等「红涨绿跌」约定属于业务层,由传入的 HTML/CSS 决定,Skill 不做干预。

高清 / 清晰度最佳实践(High-Clarity Guide)

本 Skill 的目标是「浏览器级真实渲染 + 高分辨率输出」。清晰度由三件事决定:像素密度(scale)、 JPEG 质量(quality)、字体/色彩渲染稳定性。以下给出常用组合。

1. 推荐参数组合

目标 命令要点 说明
最清晰(默认首选) --hq 自动 scale=3、quality=95,文字与细节最锐利。
指定最小宽度 --target-width 2000 保证输出宽 ≥2000px,超出部分自动放大 scale,适合大屏/印刷。
带透明背景的分享卡 --format png --bg transparent PNG 输出 alpha 通道,可叠到任意背景。
不透明白底卡片(体积小) --format jpg --hq JPG 体积小、白底干净,社交分享首选。
网页含动画/Web 字体 --wait 1000 延长稳定等待,确保字体与动画落定后再截。
C 盘紧张/不想下载 Chromium --channel msedge(或 chrome) 直接复用系统已装浏览器,跳过 ~180MB 的 Chromium 下载;清晰度参数(scale/quality)照常生效。

2. 清晰度背后的机制

  • 像素密度:--scale(即 device_scale_factor)以 2~3 倍像素密度渲染,等效 Retina, 不会因「放大图片」而模糊——它是原生高分辨率渲染,而非后期拉伸。
  • 色彩一致:Chromium 以 --force-color-profile=srgb 启动,截图颜色与浏览器一致,不偏色。
  • 文字锐利:--font-render-hinting=none + emulate_media(screen) + 显式等待 document.fonts.ready(5s 安全上限),确保 Web 字体加载完成、按屏幕样式渲染,不出现「字体未加载就截」。
  • 真实分辨率回执:成功信息会输出 resolution=WxHpx(解析 PNG/JPEG 头部得到真实像素尺寸), 可直接核对是否达到预期清晰度。

3. 判清晰度是否达标

看成功回执里的 resolution=:例如 --width 800 --hq 应得到约 2400x?px (800×3);若设 --target-width 2000 且 width=800,scale 会自动升到 2.5,输出 ≥2000px 宽。 若分辨率明显低于预期,优先检查是否误用了 --viewport-only 或 --scale 被设得过小。

Workflow / Execution Logic(执行逻辑)

按以下顺序完成一次转换:

1. 依赖就绪检查

  • 确认运行环境已安装 playwright 且已下载 Chromium: pip install playwright && playwright install chromium
  • 若未安装,脚本会以退出码 2 提示,并在 stderr 输出安装命令。先安装再重试。

2. 输入校验(Input Validation)

  • 解析 HTML 来源:优先 --html 内联;其次 --html-file / 位置参数文件。
  • 校验非空:内容为空白或长度异常时,退出码 1 并提示「HTML content is empty or invalid」。
  • 校验文件存在:指定的 --html-file 不存在时,退出码 1 并提示文件路径。

3. HTML 渲染(Rendering)

  • 启动无头 Chromium(--no-sandbox --disable-gpu --force-color-profile=srgb --hide-scrollbars --font-render-hinting=none,兼顾容器兼容与清晰渲染)。
  • 按 --width / --height 设置视口;按 --scale 设置设备缩放因子。 --hq 会把 scale 抬到 ≥3.0;--target-width 会在需要时自动抬升 scale 以满足最小输出宽度。
  • 调用 emulate_media(media="screen") 使屏幕样式(非打印样式)生效。
  • set_content(html, wait_until="load") 加载文档;随后显式 await document.fonts.ready (5s 安全上限),再停顿 --wait 毫秒,确保 Web 字体与布局稳定后再截图。
  • 背景处理:JPG 无透明通道,默认刷白底(可用 --bg 改实色);PNG 默认保留页面背景, 设 --bg transparent 则输出带 alpha 通道的透明图。

4. 图片输出(Output)

  • 根据 --format 调用 page.screenshot:PNG 无损直接输出;JPG 以 --quality(默认 92, --hq 时 ≥95)输出。
  • --full-page=True 时截取完整页面高度;否则仅截视口。
  • 输出目录自动创建;成功信息返回 {路径} ({大小} bytes, format=…, scale=…, quality=…, full_page=…, resolution=WxHpx), 其中 resolution 为解析图片头部得到的真实像素尺寸,用于核对清晰度。

5. 异常处理(Exception Handling)

情况 退出码 处理
依赖缺失 2 stderr 输出 pip install + playwright install chromium 命令
输入为空 / 文件缺失 / 格式不支持 1 stderr 明确提示具体原因
渲染引擎失败(浏览器崩溃等) 3 stderr 输出原始异常,便于定位
成功 0 打印输出路径与大小

Usage Scenarios(使用场景)

  1. HTML 报告 / 图表转图分享:把用 HTML+CSS 生成的报表、ECharts/Chart 容器等渲染成 PNG, 直接贴入文档、IM 或邮件,避免对方环境缺字体/样式。
  2. 基于模板生成分享卡片 / OG 图:用一段带样式的 HTML 模板(标题+封面+二维码)一键产出 社交分享图或 Open Graph 预览图,参数化 --width/--scale 控制尺寸与清晰度。
  3. 代码片段 / 原型可视化:将用户手写或模型生成的 HTML 片段截图成图,快速预览视觉效果, 无需手动开浏览器,便于在对话中回传结果。

Resources

scripts/

  • html_to_image.py — 核心转换脚本。直接以 CLI 调用,支持上表全部参数与退出码约定。 调用示例:
    python scripts/html_to_image.py --html "<h1>Hello</h1>" -o hello.png
    python scripts/html_to_image.py report.html -o report.jpg --format jpg --hq
    python scripts/html_to_image.py card.html -o card.png --target-width 2000
    python scripts/html_to_image.py badge.html -o badge.png --bg transparent

references/

(无——本 Skill 逻辑已完整内联于 SKILL.md,保持精简。)

Current listing version

1.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value92/100

Highlights

  • 解决高频刚需场景:HTML 报告配图、分享卡片生成、OG 图制作等
  • 基于 Playwright 实现真实浏览器级渲染,支持现代前端特性
  • 提供高清输出最佳实践,满足不同清晰度需求
Trigger Precision95/100

Highlights

  • 触发词覆盖全面:包含中英文及多种表述变体
  • 明确界定适用与不适用场景,避免误触发
  • 提供典型用户表述示例,提升匹配准确性
Structure and Standards93/100

Highlights

  • 文档结构完整:从概述到执行逻辑层层递进
  • 参数表格清晰,CLI 示例丰富实用
  • 高清指南独立成章,指导用户获得最佳输出效果
Execution Reliability91/100

Highlights

  • 异常处理机制完善:覆盖依赖缺失、输入错误、渲染失败等场景
  • 退出码约定明确,便于调用方处理
  • 支持复用系统浏览器,降低资源占用
Evidence Verifiability (mean of the first four)93/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 93, 123

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Translation pending; see source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.