Image annotator
Arrows, boxes, text, numbered steps, blur and redaction over an image, exported as a PNG and as shapes.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
src | string | — | The image to annotate. |
crossorigin | '' | 'anonymous' | 'use-credentials' | undefined | undefined | Passed to the image; anonymous lets an image from another origin with CORS be exported. |
shapes | AnnotatorShape[] | [] | The shapes, in image pixels. |
tool | AnnotatorTool | arrow | The tool in use. |
colors | string[] | ['#e11d48', '#f59e0b', '#16a34a', '#2563eb', '#18181b'] | The colours offered; the first is chosen to start. |
readonly | boolean | false | Shows the shapes with no toolbar and no editing. |
alt | string | — | The image's accessible description, read before its shapes. |
Events
| Name | Type | Description |
|---|---|---|
annotator-error | CustomEvent<AnnotatorErrorEventDetail> | An export failed, for example on a cross-origin image without CORS. |
annotation-change | CustomEvent<AnnotationChangeEventDetail> | The shapes changed: drawn, moved, resized, edited, deleted, undone or redone. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
toolbar | The toolbar. |
stage | The image and its shapes. |
image | The image. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-image-annotator--border-radius | border-radius | 8px | |
--c2-image-annotator__toolbar--background-color | color | #ffffff | |
--c2-image-annotator__toolbar--border | border | 1px solid #e4e4e7 | |
--c2-image-annotator__stage--background-color | color | #f4f4f5 | Behind the image, seen through transparent pixels. |
--c2-image-annotator__selection--color | color | rgb(2, 101, 220) | The selected shape's outline and handles. |
--c2-image-annotator__handle--size | pixel | 8px | |
--c2-image-annotator__swatch__selected--outline-color | color | rgb(2, 101, 220) | |
--c2-image-annotator__text--font-family | font-family | system-ui, sans-serif | Text shapes, on screen and in the export. |
--c2-image-annotator__number--color | color | #ffffff | The digit in a number badge. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under image-annotator, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
stage | Annotated image | — |
toolbar | Annotation tools | — |
select | Select | — |
arrow | Arrow | — |
line | Line | — |
rect | Rectangle | — |
ellipse | Ellipse | — |
pen | Pen | — |
text | Text | — |
number | Number | — |
blur | Blur | — |
redact | Redact | — |
undo | Undo | — |
redo | Redo | — |
delete | Delete | — |
color | Colour | — |
colorN | Colour {0} | {0} index |
stroke | Stroke width | — |
thin | Thin | — |
medium | Medium | — |
thick | Thick | — |
shapeArrow | Arrow | — |
shapeLine | Line | — |
shapeRect | Rectangle | — |
shapeEllipse | Ellipse | — |
shapePen | Drawing | — |
shapeText | Text | — |
shapeNumber | Number | — |
shapeBlur | Blur | — |
shapeRedact | Redaction | — |
shapeOf | {0} {1} of {2} | {0} kind {1} index {2} count |
added | {0} added | {0} kind |
deleted | {0} deleted | {0} kind |
textInput | Annotation text | — |