Skip to content

feat: Add Mosaic (pixelation) tool to annotation system#397

Open
Bae-ChangHyun wants to merge 1 commit intoxRyul:mainfrom
Bae-ChangHyun:feature/mosaic-tool
Open

feat: Add Mosaic (pixelation) tool to annotation system#397
Bae-ChangHyun wants to merge 1 commit intoxRyul:mainfrom
Bae-ChangHyun:feature/mosaic-tool

Conversation

@Bae-ChangHyun
Copy link

Summary

  • Add a new Mosaic tool (M) to the annotation system that allows users to pixelate/censor regions of an image by dragging a rectangle
  • Useful for hiding sensitive information (faces, text, personal data) before sharing screenshots
  • Fully integrated with existing undo/redo, export, presets, delete, and history systems

How it works

  1. Press M or click the Mosaic button (grid icon) to enter mosaic mode
  2. Click and drag a rectangle over the area to pixelate
  3. Adjust Block Size (5, 10, 15, 20, 30px) to control pixelation intensity
  4. Mosaic regions behave like annotations: selectable, movable, resizable, deletable
  5. Save flattens mosaic permanently into the image

Mosaic tool demo

Technical details

  • New file: src/ImageAnnotation/tools/MosaicTool.ts — Core mosaic logic with __isMosaicRegion marker to distinguish mosaic FabricImage objects from the background image
  • Pixelation algorithm: Extract region → downscale → nearest-neighbor upscale (imageSmoothingEnabled = false)
  • Edge cases handled: Background bounds clamping, tiny drag ignore (<3px), spacebar panning override, viewport zoom via getScenePoint()

Files changed

File Change
src/ImageAnnotation/tools/MosaicTool.ts NEW — MosaicTool class, MOSAIC_MARKER, isMosaicImage()
src/ImageAnnotation/types.ts Add ToolMode.MOSAIC, MOSAIC_BLOCK_SIZES
src/ImageAnnotation/managers/ToolManager.ts Mosaic mode state, toggle, interactivity
src/ImageAnnotation/ui/ToolbarBuilder.ts Mosaic button + block size controls
src/ImageAnnotation/ImageAnnotationModal.ts MosaicTool integration, M hotkey, mouse events
src/ImageAnnotation/managers/HistoryManager.ts Mosaic marker serialization/restore
src/ImageAnnotation/export/ImageExporter.ts Index-based background detection (avoid mosaic confusion)
src/ImageConverterSettings.ts Mosaic presets
styles.css Block size controls styles
docs/Annotation tool.md Mosaic section + screenshot
tests/ Updated mocks for mosaic compatibility

Test plan

  • npm run build — passes
  • npm run lint — 0 errors
  • npm run test — all annotation tests pass (pre-existing unrelated failures only)
  • Manual test: M key → drag rectangle → pixelation applied
  • Manual test: Block size change → re-drag → different pixelation
  • Manual test: Ctrl+Z/Y undo/redo works with mosaic regions
  • Manual test: Select mosaic → Delete removes it
  • Manual test: Save → image file has mosaic baked in

Add a new Mosaic tool (M) that allows users to pixelate/censor regions
of an image by dragging a rectangle. Useful for hiding sensitive
information (faces, text, personal data) before sharing screenshots.

- New MosaicTool class with drag-to-pixelate interaction
- Block size control (5, 10, 15, 20, 30px)
- Full integration with undo/redo, export, presets, and delete
- Mosaic marker (`__isMosaicRegion`) to distinguish from background image
- Keyboard shortcut: M key
- Updated docs and tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant