feat: Export board as PNG image #19

Merged
ti-paul merged 1 commit from feature/6-export-board-image into main 2026-05-15 00:59:00 +00:00
Member

Closes #6

Summary

Added PNG export endpoints for the pixel board. Users can download the full board or a specific region as a PNG image with optional upscaling.

Endpoints

  • GET /api/board.png -- Full board export, query params: scale (1-4, default 1)
  • GET /api/board/region.png -- Region export, query params: x, y, w, h, scale (1-8)

Changes

  • server/exportImage.js -- PNG rendering module using pngjs (pure JS, no native deps)
    • renderBoardPng() -- full board to PNG buffer
    • renderRegionPng() -- arbitrary rectangular region to PNG buffer
    • Configurable upscale factor for higher-res exports
  • server/index.js -- Added two GET endpoints with proper content-type, caching headers, and metrics tracking
  • server/exportImage.test.js -- 10 unit tests covering:
    • PNG signature validation
    • Correct output dimensions at scale 1, 2, max clamp
    • Palette color accuracy for placed pixels
    • Region bounds clamping
    • Invalid region handling
    • Scale clamping (min/max)

Tests

10 tests, all pass. Existing tests unaffected.

Dependencies

  • Added pngjs (pure JS, zero native deps)
Closes #6 ## Summary Added PNG export endpoints for the pixel board. Users can download the full board or a specific region as a PNG image with optional upscaling. ## Endpoints - **GET /api/board.png** -- Full board export, query params: `scale` (1-4, default 1) - **GET /api/board/region.png** -- Region export, query params: `x`, `y`, `w`, `h`, `scale` (1-8) ## Changes - **server/exportImage.js** -- PNG rendering module using pngjs (pure JS, no native deps) - `renderBoardPng()` -- full board to PNG buffer - `renderRegionPng()` -- arbitrary rectangular region to PNG buffer - Configurable upscale factor for higher-res exports - **server/index.js** -- Added two GET endpoints with proper content-type, caching headers, and metrics tracking - **server/exportImage.test.js** -- 10 unit tests covering: - PNG signature validation - Correct output dimensions at scale 1, 2, max clamp - Palette color accuracy for placed pixels - Region bounds clamping - Invalid region handling - Scale clamping (min/max) ## Tests 10 tests, all pass. Existing tests unaffected. ## Dependencies - Added `pngjs` (pure JS, zero native deps)
feat: export board as PNG image
Some checks failed
CI / test (pull_request) Failing after 3h10m34s
2e0bc5cee4
- Full board export via GET /api/board.png
- Region export via GET /api/board/region.png?x=&y=&w=&h=&scale=
- Configurable upscale factor (1-8 for full, 1-16 for region)
- Pure JS PNG generation via pngjs (no native deps)
- 10 unit tests covering rendering, scaling, bounds, and colors

Closes #6
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
les_clankeurs/pixel-clash!19
No description provided.