Image annotator
Arrows, boxes, text, numbered steps, blur and redaction over an image, exported as a PNG and as shapes.
c2-image-annotator is the markup step of a bug report, a support ticket or a design review: point at what is wrong with an arrow or a box, number the steps, write a note, and blur or redact what should not be shared, then export the result.
Import
import '@c2n/components/image-annotator'Usage
Tools
The toolbar offers Select, Arrow, Line, Rectangle, Ellipse, Pen, Text, Number, Blur and Redact, a row of colours (colors), three stroke widths, and Undo and Redo (also Ctrl/⌘+Z and Shift+Ctrl/⌘+Z). Drag to draw; click to place text or a number. Shift keeps lines at 45° steps and boxes square. Select moves a shape, resizes it by its handles, and deletes it with Delete or the toolbar button.
Shapes and export
Shapes are plain objects in the image’s own pixels, so they stay in place at any display size. Read or set them with shapes; annotation-change gives the list after every edit, ready to save with the ticket:
const annotator = document.querySelector('c2-image-annotator')!
annotator.addEventListener('annotation-change', (event) => draft.save(event.detail.shapes))
const blob = await annotator.toBlob() // PNG at the image's natural sizetoBlob(), toDataURL() and toCanvas() draw the image at full size with the shapes on it. Redactions are drawn above every other shape, so a later blur never uncovers them. In the export a redaction replaces the pixels and a blur is a coarse pixelation, so text under either cannot be recovered; use Redact for passwords, keys and card numbers. An image from another origin can only be exported with CORS: set crossorigin="anonymous" and serve it with Access-Control-Allow-Origin. Otherwise the export rejects and annotator-error says why.
Keyboard
With a drawing tool chosen, Enter on the image adds a shape in the middle. With Select, Tab reaches each shape (named “Rectangle 1 of 3”), the arrow keys nudge it (Shift for 10 pixels), Enter edits a text, and Delete removes it. Additions and deletions are announced. readonly shows the shapes with no toolbar, for the ticket view.