绘制 RasterScene¶
from entari_plugin_htmlrender.graphics import (
FillRect,
GraphicsRenderer,
PixelRect,
RasterScene,
RGBAColor,
)
async def draw(graphics: GraphicsRenderer) -> bytes:
scene = RasterScene(
width=320,
height=180,
background=RGBAColor(15, 23, 42),
commands=(
FillRect(
PixelRect(32, 32, 256, 116),
RGBAColor(139, 92, 246),
),
),
)
return bytes(await graphics.rasterize(scene))
Entari handler 传入 service.graphics。Pillow 与 Skia 实现同一个GraphicsRenderer;graphics.backend 在 composition 中选择实现,业务函数不按backend 分支。
场景使用物理像素、半开矩形与概念上的 source-over 合成,但不保证两个 native encoder 产生逐字节或逐像素相同输出。它们不是 HTML Provider,也不提供文本布局。