marker.js 2 - Image Annotation

2.32.7 · deprecated · verified Sun Apr 19

marker.js 2 is a JavaScript browser library designed to enable image annotation functionality within web applications. It allows users to mark up, highlight, and add comments to images directly in the browser, and then save or process the annotated results. While still supported for some time, this version (2.x, with current stable being 2.32.7) is officially deprecated in favor of marker.js 3, which is the focus of all future development. Releases for marker.js 2 were frequent, often several patch versions per month, but this cadence is expected to slow significantly as focus shifts to v3. Its key differentiator was providing a complete, out-of-the-box UI for image annotation with various tools.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `marker.js 2` on an existing image element, open its annotation UI, and handle the `render` event to update the image source with the annotated version.

import * as markerjs2 from 'markerjs2';

// Imagine an image element exists in the DOM
document.body.innerHTML = '<img id="myimg" src="https://picsum.photos/800/600?random=1" alt="Image to annotate" style="max-width: 100%;" />';

const imgElement = document.getElementById('myimg');

if (imgElement) {
  let markerArea = new markerjs2.MarkerArea(imgElement);

  markerArea.addEventListener('render', (event) => {
    // Replace the original image with the annotated one
    // In a real app, you might upload event.dataUrl to a server
    // or display it in a new element.
    if (imgElement instanceof HTMLImageElement) {
      imgElement.src = event.dataUrl;
      console.log('Annotation rendered. Data URL length:', event.dataUrl.length);
    }
  });

  // Open the marker.js UI after a short delay to ensure image loads
  setTimeout(() => {
    markerArea.show();
  }, 500);
} else {
  console.error('Image element with ID "myimg" not found.');
}

view raw JSON →