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

easyannotation

v2.0.6

Published

Image annotation in JavaScript

Downloads

927

Readme

Easy Annotation - a JavaScript library to annotate pictures online

Features

  • Add different shapes to your pictures
  • Highlight some part of the image
  • Blur parts of the image
  • Save to PNG, JSON or XML
  • Load previously saved work
  • Simple usage
  • Zero dependencies
  • Responsive and auto-positioning
  • Supports touch devices

Getting Started

Installation

Install via npm:

npm i easyannotation

Include code:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/easyannotation"></script>

Example

  new easyannotation.AnnotatorContainer(document.querySelector('#inputImage')).show(function(res) {
      //process result when user press Save
      document.querySelector('#sample4Res').src = res;
  });

Options

  new easyannotation.AnnotatorContainer(document.querySelector('#inputImage'), {
     
     // optional target element to place the EasyAnnotation container.
     // If not specified container will be placed on document.body element.
     targetElement: document.body,
    
     // default ui for Easy Annotation toolbar and buttons.
     // Currently supported values are 'default' and 'dark'.
     ui: 'default',

     //default font to be used for text elements.
     font: {
        name: 'Arial', // font name
        size: 24,      //default font size
        bold: false,   //bold
        italic: false  //italic
     },
    
     // the drawing style for lines, the following options can be used:
     drawStyle: {
     //   startArrow and endArrow properties define the start and end of lines, can be one of the follwing:
     //     *   ArrowType.NONE - no arrow
     //     *   ArrowType.ARROW - simple arrow
     //     *   ArrowType.OPEN_ARROW - simple open arrow
     //     *   ArrowType.RECT - rectangle arrow
     //     *   ArrowType.DIAMOND_ARROW - diamond arrow
     //     *   ArrowType.OVAL_ARROW - oval arrow
     //     *   ArrowType.LINE_ARROW - vertical line arrow
          startArrow: ArrowType.NONE, 
          endArrow: ArrowType.NONE,

     //   line type, can be one of the follwing:
     //     *  StrokeType.SOLID - solid line
     //     *  StrokeType.DOTTED - dotted line
     //     *  StrokeType.DASHED - dashed line
        type: easyannotation.StrokeType.SOLID,
        
        width: 1, //   Line width, can be any number starting with 1
        color: '#000' // default line color
     },

    // Individual draw style for each annotator.
    // If specified this style will be used when adding an annotator of the specified type.
    drawStyles: {
        line: DrawStyle,
        arrow: DrawStyle,
        rect: DrawStyle,
        polygon: DrawStyle,
        callout: DrawStyle,
        ellipse: DrawStyle
    },

     //default fill style for shapes that can be filled, the following options can be used:
     fillStyle: {
          fillType: 0, // a number between 0 and 9 defining the fill type. 
                      // If 0 is specified, elements will fill with solid background.
          opacity: 100,  // default opacity fill for components, 100 - opaque, 0 - transparent
          color: '#000' // default fill color
     },
    
    // optional fill style for each annotator.
    // If specified this style will be used when adding an annotator of the specified type.
    fillStyles: {
        text: FillStyle,
        rect: FillStyle,
        polygon: FillStyle,
        callout: FillStyle,
        ellipse: FillStyle
    },

     x: null, //x position based on target element
     y: null, //y position based on target element
     width: null, //with of the container element. If not specified defaults to image width.
     height: null, //height of the container element. If not specified defaults to image height.
  
     loadOnClick: boolean, //if true, annotator will load when user click or tap on the image element

     showClose: boolean,//if true, close button will show

     showToolbar: true, //true to show annotation toolbar
     showProperties: true, // true to show properties toolbar

     style: null, //additional style properties to apply to Easy Annotation container element

     // a list of items to add to toolbar element, by default contains the following items:
     toolbarItems: [
                    {
                        //clear button to delete selected or all elements
                        itemId: 'delete',
                        iconSVG: EraseIcon,
                        title: 'Delete selected or all elements'
                    },
                    {xtype: 'text'},     //text element
                    {xtype: 'line'},     //line element
                    {xtype: 'arrow'},    //arrow element
                    {xtype: 'ellipse'},   //ellipse/circle element
                    {xtype: 'rect'},      //rectangle element
                    {xtype: 'callout'},   //callout element
                    {xtype: 'image'},     //image element
                    {xtype: 'blur'},      //bluring element to blur parts of the image
                    {xtype: 'free-draw'}, //free draw element
                    {xtype: 'polygon'},   // polygon draw element
                    {
                        //save element
                        itemId: 'save',
                        iconSVG: SaveIcon,
                        title: 'Save changes and close annotator'
                    }],

     //Hide original image element. 
     //If false, image element won't be hidden and EasyAnnotation container will be placed above the original image
     hideElement: true,

    // default text to show when users adds a new Text annotator
    // by default this is "Text" string
    defaultText: null,
    
    //an optional object with label translations. 
    // The following are the keys and default values for dialog labels.
    // * color - 'Color'
    // * transparency - 'Transparency'
    // * blurRadius - 'Blur Radius'
    // * lineStyle - 'Line Style'
    // * drawLineWidth - 'Width'
    // * fillPattern - 'Fill Pattern'
    // * fillEffects - 'Effects'
    // * textFont - 'Font'
    // * textSize - 'Size'
     translations: null
    
  }).show(function(res) {
      //process result when user press Save
      document.querySelector('#sample4Res').src = res;
  });

Methods

  • show(callback:function, exportType:ExportType) - Show EasyAnnotation container and provide callback to be called when user save changes.
  • addElement(element:BaseAnnotator) - Add new annotator element.
  • selectAll() - select all elements
  • deselectAll() - deselect all elements
  • clear() _- delete all elements from the container _
  • save(callback:function, exportType:ExportType) - save data to specified format and call callback function when done. Data can be saved as PNG, JSON or XML. Callback function will be called with one string argument with saved data in the required format
  • loadXML(xml:string) - load data from specified XML string. xml parameter must be a valid XML result from show or save functions.
  • loadJSON(json:string) - load data from specified JSON string. json parameter must be a valid JSON result from show or save functions.

License

(see LICENSE for details) - library is free of charge for Open Source projects and for personal use only. Other projects require a license.

For more details, please visit EasyAnnotation.com website.