AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Image Resizer in the alexandrai-tools project.
Project overview
This guide covers src/tools/image-resizer. computeResize returns original dimensions when no target is provided, preserves aspect ratio from width or height, gives width priority when both dimensions are provided with aspect ratio enabled, and uses exact dimensions when aspect ratio is disabled. Body.astro draws the loaded image to an output canvas and downloads resized.png.
Primary source files
- src/tools/image-resizer/index.ts defines meta, ResizeDimensions, and computeResize.
- src/tools/image-resizer/index.test.ts covers width scaling, height scaling, width priority, exact sizing, original dimensions, and square images.
- src/tools/image-resizer/Body.astro owns image loading, width and height inputs, keep-aspect control, canvas drawing, PNG download, and clear state.
- src/tools/image-resizer/i18n.ts owns localized labels.
- src/lib/tools.ts registers the tool metadata.
Setup commands
npm install npm test npm run typecheck npm run build npm run dev
Change rules
- Do not resize until at least one target dimension is provided in the UI.
- When keepAspect is true and both targets exist, width is authoritative.
- Use Math.round for computed aspect-ratio dimensions.
- When keepAspect is false, preserve missing dimensions from the source image.
- Set the output canvas dimensions before drawing.
- Download PNG output from the canvas.
- Keep resizing browser-local and avoid hidden uploads.
Testing
Test all computeResize branches, zero and missing inputs at the UI layer, tall and wide source images, square images, no-target validation, output canvas dimensions, download filename, and clear-state reset.
PR checklist
- npm test passes for image-resizer.
- Canvas processing stays browser-local and deterministic enough for tests.
- Pure helper behavior, UI controls, and i18n labels stay aligned.
- Download format, filename, and reset behavior are covered.