npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@markerjs/markerjs3

v3.0.0-beta.0

Published

marker.js 3

Downloads

92

Readme

marker.js 3 — Add image annotation to your web apps

Note: marker.js 3 is in the pre-release stage of its lifecycle and will have many additions and, potentially, breaking changes before the official 3.0 release.

If you need a stable image annotation library, consider using marker.js 2 for now.

marker.js 3 is a JavaScript browser library to enable image annotation in your web applications. Add marker.js 3 to your web app and enable users to annotate and mark up images. You can save, share or otherwise process the results.

Installation

npm install @markerjs/markerjs3

or

yarn add @markerjs/markerjs3

Usage

Unlike the previous version, marker.js 3 is a "headless" (sort of) library. In this case "headless" means that it doesn't come with any toolbars, property editors, and placement preconceptions. This way the library focuses on the core features you need, and you can make it feel totally native in the application you are building without resorting to any tricks or hacks.

With that out of the way, here are the simplest usage scenarios...

MarkerArea (The Editor)

Import MarkerArea from @markerjs/markerjs3:

import { MarkerArea } from '@markerjs/markerjs3';

In the code below we assume that you have an HTMLImageElement as targetImage. It can be a reference to an image you already have on the page or you can simply create it with something like this:

const targetImg = document.createElement('img');
targetImg.src = './sample.jpg';

Now you just need to create an instance of MarkerArea, set its targetImage property and add it to the page:

const markerArea = new MarkerArea();
markerArea.targetImage = targetImg;
editorContainerDiv.appendChild(markerArea);

To initiate creation of a marker you just call createMarker() and pass it the name (or type) of the marker you want to create. So, if you have a button with id addFrameButton you can make it create a new FrameMarker with something like this:

document.querySelector("#addButton")!.addEventListener("click", () => {
  markerArea.createMarker("FrameMarker");
});

And whenever you want to save state (current annotation) you just call getState():

document.querySelector("#saveStateButton")!.addEventListener("click", () => {
  const state = markerArea.getState();
  console.log(state);
});

Rendering static images

To render the annotation as a static image you use Renderer.

import { MarkerArea, Renderer } from '@markerjs/markerjs3';

Just create an instance of it and pass the annotation state to the rasterize() method:

const renderer = new Renderer();
renderer.targetImage = targetImg;
const dataUrl = await renderer.rasterize(markerArea.getState());

const img = document.createElement('img');
img.src = dataUrl;

someDiv.appendChild(img);

MarkerView (The Viewer)

To show dynamic annotation overlays on top of the original image you use MarkerView.

import { MarkerView } from '@markerjs/markerjs3';

const markerView = new MarkerView();
markerView.targetImage = targetImg;
viewerContainer.appendChild(markerView);

markerView.show(savedState);

Demos

Check out the "work-in-progress" demo here. It covers most of the available features with no extra bells or whistles.

While it's made with React it is purposefully light on React-specific stuff and "best practices" to just focus on marker.js 3 related things.

more demos coming soon...

More docs and tutorials

coming soon...

License

Linkware (see LICENSE for details) - the UI displays a small link back to the marker.js 3 website which should be retained.

Alternative licenses are available through the marker.js website.