Implementation:1ay1 Agentty Image Dimension Parser
| Knowledge Sources | |
|---|---|
| Domains | Images, Parsing |
| Last Updated | 2026-10-28 12:00 GMT |
Overview
Reads an image's pixel dimensions straight from its header bytes with no decode and no external codec, preventing Anthropic 400s for oversized images.
Description
The agentty::util::image_dimensions function reads pixel dimensions from the leading bytes of a PNG, GIF, JPEG, or WebP — with no decode and no external codec. Returns `{0,0}` for unrecognised/truncated headers (callers treat unknown as "can't tell → allow", since a guess-block would be worse than the occasional provider 400).
Why this exists: Anthropic 400s a whole turn when ANY image in a many-image request exceeds 2000 px on a side. A tiny 48 KB screenshot can easily be 3000+ px wide (flat UI compresses small), so file size is no guard — real dimensions must be read. Header-only so both the wire layer and the composer can consult it.
Usage
Import this when you need to: check if an image exceeds provider dimension limits before sending, or read pixel dimensions from image header bytes.
Code Reference
Source Location
- Repository: 1ay1_Agentty
- File: include/agentty/util/image_dims.hpp
- Lines: 1-132
Signature
namespace agentty::util {
struct ImageDims {
unsigned w = 0;
unsigned h = 0;
[[nodiscard]] bool known() const noexcept { return w != 0 && h != 0; }
[[nodiscard]] unsigned longest() const noexcept { return w > h ? w : h; }
};
// Parse dimensions from PNG / GIF / JPEG / WebP header bytes. Never throws.
[[nodiscard]] inline ImageDims image_dimensions(std::string_view bytes) noexcept;
}
Import
#include "agentty/util/image_dims.hpp"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| bytes | std::string_view | Yes | The leading bytes of an image file |
Outputs
| Name | Type | Description |
|---|---|---|
| ImageDims | struct | w, h; {0,0} when unrecognised/truncated |
| known() | bool | True when both w and h are non-zero |
| longest() | unsigned | max(w, h) — for 2000-px limit checks |
Usage Examples
Check Image Dimensions
#include "agentty/util/image_dims.hpp"
auto bytes = read_file("screenshot.png");
auto dims = agentty::util::image_dimensions(bytes);
if (dims.known() && dims.longest() > 2000) {
// Anthropic would 400 this — resize or warn before sending
}