A simple web service that converts HTML/templates to images, with image lifecycle management support.
PORT: Service port, default is 8999IMAGE_LIFETIME_HOURS: Image lifetime in hours, default is 24 hours. Images older than this will be automatically cleaned upSTORAGE_BACKEND: Image storage backend. Supportslocal(default),s3, andr2
When running multiple replicas, JSON-mode images can be stored in one shared
S3-compatible bucket. This prevents a later image request from returning 404
when it reaches a replica other than the one that rendered the image. API paths
and response formats remain unchanged.
STORAGE_BACKEND=r2
S3_ENDPOINT_URL=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
S3_BUCKET=astrbot-t2i
AWS_ACCESS_KEY_ID=<ACCESS_KEY_ID>
AWS_SECRET_ACCESS_KEY=<SECRET_ACCESS_KEY>
AWS_DEFAULT_REGION=auto
S3_PREFIX=imagesConfigure an object lifecycle rule on the bucket to expire old images.
IMAGE_LIFETIME_HOURS only cleans up local files and does not delete objects.
Convert HTML to image
Choose either html or tmpl. Provide tmpl and tmpldata together.
strhtml: HTML textstrtmpl: Jinja2 HTML templatedicttmpldata: Jinja2 template databooljson: Whether to return JSON format (returns an id)dictoptionaloptions- timeout (float, optional): Screenshot timeout.
- type (Literal["jpeg", "png"], optional): Screenshot image type.
- quality (int, optional): Screenshot quality, only applicable to JPEG format.
- omit_background (bool, optional): Whether to hide the default white background, allowing transparent screenshots (PNG only).
- full_page (bool, optional): Whether to capture the entire page instead of just the viewport, default is True.
- clip (FloatRect, optional): Area to clip after screenshot, xy is the starting point.
- animations: (Literal["allow", "disabled"], optional): Whether to allow CSS animations.
- caret: (Literal["hide", "initial"], optional): When set to
hide, the text caret will be hidden during screenshot, default ishide. - scale: (Literal["css", "device"], optional): Page scaling settings. When set to
css, device resolution maps 1:1 with CSS pixels, making screenshots smaller on high-DPI screens. When set todevice, scales according to device screen scaling or the device_scale_factor parameter in the current Playwright Page/Context. - viewport_width (int, optional): Custom viewport width to control screenshot width. Resolved in priority order:
- Explicitly set in request options
- Auto-parsed from
<meta name="viewport" content="width=...">in HTML - Defaults to 800px if not specified and no meta tag found
- viewport_height (int, optional): Custom viewport height to control screenshot height. Resolved in priority order:
- Explicitly set in request options
- Auto-parsed from
<meta name="viewport" content="height=...">in HTML - Defaults to 720px if not specified and no meta tag found
- device_scale_factor_level (Literal["normal", "high", "ultra"], optional): Device pixel ratio level, default is "normal". Different levels use independent browser context pools for better performance and resource isolation.
normal: Device pixel ratio 1.0 (default)high: Device pixel ratio 1.3ultra: Device pixel ratio 1.8
Returns the corresponding image by id.