mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
When an image needs resizing, `resizeImageInProcess` builds a list of encodings: PNG first, then JPEG at decreasing qualities. It returned the first one under `maxBytes`. Since PNG was always first, it was used whenever it fit, even when it was many times larger than the JPEG. The doc comment says "Try both PNG and JPEG formats, pick the smaller one", and the code worked that way before v0.62.0. Because of this, photos were sent as multi-MB PNGs, which made requests large enough to fail or time out. This change compares PNG with JPEG at the configured quality at each size step and tries the smaller one first. It tries the other one next, and the lower JPEG qualities only after that. Screenshots and other images where PNG is smaller still go out as PNG. **Testing** - Added a regression test to `test/image-processing.test.ts`: a generated photo-like 1200×800 JPEG resized to 1000 px must come back as `image/jpeg`. The test fails without the fix (PNG is returned) and passes with it. - `node ../../node_modules/vitest/dist/cli.js --run test/image-processing.test.ts test/image-resize-callers.test.ts`: all pass. - `npm run check`: no issues in the changed files. It does report type errors, all in `packages/ai/test` (model ID unions), which this change does not touch. - Reproduction with a photo-like 2400×1620 JPEG (460 KB base64): - before: `image/png`, 4,008,480 bytes base64, at 2000×1350 - after: `image/jpeg`, 255,316 bytes base64, at 2000×1350 Fixes #11551 Requested by @davidbrai Co-authored-by: triagent <triagent@localhost> |
||
|---|---|---|
| .. | ||
| agent | ||
| ai | ||
| chord | ||
| codemode | ||
| coding-agent | ||
| durable | ||
| env | ||
| evals | ||
| mcp | ||
| telemetry | ||
| tui | ||