djaodjin / djaodjin-annotate

Simple jquery plugin to annotate a screenshot
MIT License
63 stars 51 forks source link

djaodjin-annotate.js

djaodjin-annotate.js is a simple jquery plugin allowing you to annotate a screenshot. Try the live demo on DjaoDjin blog.

Usage

Load djaodjin-annotate.css and djaodjin-annotate.js

<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8 />
    <title></title>
    <link rel="stylesheet" type="text/css" href="https://github.com/djaodjin/djaodjin-annotate/blob/master/static/css/annotate.css" />
</head>
<body>

    <script type="text/javascript" src="https://github.com/djaodjin/djaodjin-annotate/raw/master//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="https://github.com/djaodjin/djaodjin-annotate/raw/master/static/js/djaodjin-annotate.js"></script>
</body>
</html>

Just add a div element inside `body.

<div id="myCanvas"></div>

and on a script:

$(document).ready(function(){
    $("#myCanvas").annotate(options);
});

customizable options:

options = {
    width: "640",           // Width of canvas
    height: "400",          // Height of canvas
    color:"red",            // Color for shape and text
    type : "rectangle",     // default shape: can be "rectangle", "arrow" or "text"
    images: null,           // Array of images path : ["images/image1.png", "images/image2.png"]
    linewidth:2,            // Line width for rectangle and arrow shapes
    fontsize:"20px",        // font size for text
    bootstrap: true,        // Bootstrap theme design
    position: "top",        // Position of toolbar (available only with bootstrap)
    idAttribute: "id",      // Attribute to select image id.
    selectEvent: "change",  // listened event to select image
    unselectTool: false     // display an unselect tool for mobile
    onExport: function(image){} // Action when export function is called, with data uri as params (default log to console)
}

Destroy an annotate

Once initialized, it can be destroy:

$("#myCanvas").annotate("destroy");

Add image to existing annotate

It's also possible to provide new images by pushing them:

$("#myCanvas").annotate("push", {id:"unique_identifier", path: "images/test_2.jpg"});

Export image

$("#myCanvas").annotate("export", exportOptions);

Returns the image in Data URI format.

{
    type: "image/jpeg"  // ex: "image/png"
    quality: 0.75       // Available only for "image/jpeg"
}

Events

ex:

    $('#myCanvas').on("annotate-image-added", function(event, id, path){
        $(".my-image-selector").append("<label><input type=\"radio\" name=\"image-selector\" class=\"annotate-image-select\" id=\"" + id + "\" checked><img src=\"" + path + "\" width=\"35\" height=\"35\"></label>");
    });

If multiple images provided, an image selector is necessary to switch. Image selector must trigger an event on annotate-image-select class. you can custom the event by using selectEvent option (default: change) and custom the readable image attribute by using idAttribute option (default: id)

Contributing

The djaodjin-annotate project is using Google Javascript style guidelines, mechanically enforced through the eslint-config-google eslint plug-in. Thank you to @Josephdias92 for the initial work on this.

Release notes

v0.0.4

v0.0.3

v0.0.2

v0.0.1

License

Copyright (c) 2015, Djaodjin Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.