Expand description
Image mechanics shared by tools and the wire layer: magic sniffing,
header-only dimension reads, the downscale-to-fit pass, and the
per-image / per-message byte budget that keeps request bodies under the
gateway’s limit (the HTTP 413 cure — see apply_image_budget).
One source of truth for “is this bytes stream a picture, how big is it,
and does it fit the wire”: the read_image tool sniffs and labels with
it, and the engine budgets and shrinks with it. Numbers live here as
named constants so a product can argue with them in one place.
Structs§
- Image
Budget Error - Why the request never left the machine: the full size inventory of every picture it carried, plus the lines that crossed the budget. Surfaced as a run error — the request is refused WHOLE, never thinned.
Constants§
- MAX_
IMAGE_ BASE64_ BYTES - Per-image wire budget, in base64 characters (the on-the-wire size). ~2.6 MB of raw pixels — after the downscale pass only the most pathological screenshot can reach it, and such a one is refused with an inventory instead of silently thinned.
- MAX_
MESSAGE_ IMAGES_ BASE64_ BYTES - Per-message wire budget for all of its pictures together, in base64 characters. A message keeps all of its pictures or none — this is the line where “all” stops being affordable and the send is refused.
- MAX_
WIRE_ LONG_ EDGE - Longest edge any picture may carry on the wire: large enough for a desktop screenshot’s text to stay legible to a vision model, small enough that two of them never tripped the gateway’s body limit (the HTTP 413 of session 20261030_862ddf5c).
Functions§
- apply_
image_ budget - Prepare every picture for the wire and enforce the byte budget.
- base64_
len - On-the-wire size of a raw payload once base64-encoded, without doing the
encode: padded standard base64 is
ceil(n / 3) * 4characters. - base64_
prefix_ dims - Read a picture’s pixel size from the HEAD of its base64 payload — a
bounded probe, never a full decode.
Nonewhen the head carries no decodable PNG/JPEG header: an exotic format, a corrupt payload, or not an image at all. Non-ASCII characters are skipped (a payload may be arbitrary text), so the probe never slices mid-character. - downscale_
to_ fit - Shrink a picture so its longest edge is
MAX_WIRE_LONG_EDGE, re-encoding in the SAME format (a PNG screenshot stays lossless, a JPEG stays a JPEG). Returns the (possibly unchanged) bytes plus the original and final pixel sizes. - from_
base64 - Decode base64 with the standard alphabet.
- header_
dimensions - Header-only dimension read for PNG/JPEG — no pixel decode.
Nonefor bytes that are not a decodable PNG/JPEG stream. - sniff_
mime - MIME sniff from magic bytes — the extension and any declared MIME are
advisory at best (a
.jpgthat is really a PNG is a PNG; atext/htmlwearingimage/pngis not a picture at all). - to_
base64 - Encode to base64 (standard alphabet, padded).
Type Aliases§
- Dims
- A picture’s pixel size, (width, height).