Annotating An Image In JavaScript – Annotorious

Category: Image , Javascript , Recommended | July 12, 2020
Author: recogito
Views Total: 111 views
Official Page: Go to website
Last Update: July 12, 2020
License: BSD-3-Clause


Annotating An Image In JavaScript – Annotorious


Annotorious is a simple yet feature-rich JavaScript image annotation library that adds custom comments, notes, tags to a specific part of an image.


  • Load pre-defined annotations from a JSON file.
  • Drag and drop to create new annotations from an editor popup.
  • Based on W3C WebAnnotation model.

How to use it:

1. Install and import the Annotorious as a module.

$ npm install @recogito/annotorious --save
import { Annotorious } from '@recogito/annotorious';

2. Or download the package and insert the annotorious.min.js into the HTML document.

<script src="annotorious.min.js"></script>

3. Initialize the Annotorious on the image and we’re ready to go.

<img id="example" src="example.jpg" />
var anno = Annotorious.init({
    image: 'example'

4. Define your annotations in a w3c.json file and load it on page load.

// annotations.w3c.json
    "@context": "",
    "id": "#unique-ID-Here",
    "type": "Annotation",
    "body": [{
      "type": "TextualBody",
      "value": "Comments Here"
    }, {
      "type": "TextualBody",
      "purpose": "tagging",
      "value": "Tag 1"
    }, {
      "type": "TextualBody",
      "purpose": "tagging",
      "value": "Tag 2"
    "target": {
      "selector": [{
        "type": "FragmentSelector",
        "conformsTo": "",
        "value": "xywh=pixel:270,120,90,170"

3. Enable read-only mode. Defaults to false.

var anno = Annotorious.init({
    image: 'example',
    readOnly: true

4. Disable the editor popup. Defaults to false.

var anno = Annotorious.init({
    image: 'example',
    headless: true

5. Add a new annotation to the image following the structure you’ve seen in the annotations.w3c.json.

// add an annotation
anno.addAnnotation(annotation [, readOnly]);

// add an array of annotations

6. Remove an annotation from the image.


7. Get all annotations.


8. Select an annotation.

// select the current annotation

// select a specific annotation

9. Show/hide the annotations.


10. Apply a custom template to the annotation.

anno.applyTemplate(template, openEditor[TRUE/FALSE]);

11. Destroy the instance.


12. Event handlers.

anno.on('selectAnnotation', function(annotation) {
  console.log('selected', annotation);

anno.on('createAnnotation', function(a) {
  console.log('created', a);

anno.on('updateAnnotation', function(annotation, previous) {
  console.log('updated', previous, 'with', annotation);

anno.on('deleteAnnotation', function(annotation) {
  console.log('deleted', annotation);

anno.on('mouseEnterAnnotation', function(annotation, event) {
  console.log('mouseEnter', annotation);

anno.on('mouseLeaveAnnotation', function(annotation, event) {
  console.log('mouseLeave', annotation);


v2.0.4 (07/12/2020)

  • Beta support for rendering any SVG shape contained in W3C Web Annotations
  • Beta support for polygon drawing
  • Various bugfixes
  • Portuguese UI translation
  • Tag widget: controlled vocabulary autosuggest
  • Selecting an annotation now adds a selected CSS class

v2.0.3 (06/12/2020)

  • Various smaller bugfixes
  • Microsoft Edge compatibility
  • Experimental support for responsive images
  • Web Annotation standard compliance: target now includes a source property with the image source URL
  • Minor API changes: selectAnnotation method now returns selected annotation object and does not fire the selectAnnotation event
  • Added support for internationalization
  • Ability to handle user information for UI display and when creating/updating annotations
  • Ability to add created and modified timestamps, with an option for the host application to sync with the server time

v2.0.2 (05/21/2020)

  • Minor bugfixes
  • Enabling readOnly annotations

v2.0.2 (05/21/2020)

  • Minor bugfixes

You Might Be Interested In:

Leave a Reply