#ai-generated
Summary
Produce a small, context-budget-friendly preview of an image asset for inline display in an MCP tool result: downscale with Pillow and encode to WebP under a size cap, with a graceful "too large → metadata only" fallback.
Footprint (new/changed files)
src/lib_python_comfy/preview.py:
encode_preview(image_bytes, *, max_dim=512, max_b64_chars=100_000, quality=70) -> PreviewResult (raw WebP bytes + base64 + whether it fit the budget)
tests/test_preview.py — uses a generated in-memory test image (no network).
Acceptance criteria
- Output respects
max_dim and stays under max_b64_chars; quality steps down if needed.
- Non-image / undecodable input fails cleanly with a clear error (caller can fall back to metadata).
- Pure function over bytes — no client/network dependency.
Dependencies
- Must come after L1 (Pillow dep) and L5 (operates on asset bytes /
Asset). blocked_by set for both.
Notes
Mirrors encode_preview_for_mcp / view_image in the reference. The MCP-side view_image tool (wrapper ticket A4) calls this.
#ai-generated
Summary
Produce a small, context-budget-friendly preview of an image asset for inline display in an MCP tool result: downscale with Pillow and encode to WebP under a size cap, with a graceful "too large → metadata only" fallback.
Footprint (new/changed files)
src/lib_python_comfy/preview.py:encode_preview(image_bytes, *, max_dim=512, max_b64_chars=100_000, quality=70) -> PreviewResult(raw WebP bytes + base64 + whether it fit the budget)tests/test_preview.py— uses a generated in-memory test image (no network).Acceptance criteria
max_dimand stays undermax_b64_chars; quality steps down if needed.Dependencies
Asset).blocked_byset for both.Notes
Mirrors
encode_preview_for_mcp/view_imagein the reference. The MCP-sideview_imagetool (wrapper ticket A4) calls this.