GithubHelp home page GithubHelp logo

mauricioac / djaodjin-annotate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from djaodjin/djaodjin-annotate

0.0 2.0 0.0 736 KB

Simple jquery plugin to annotate a screenshot

License: MIT License

JavaScript 93.10% CSS 0.91% HTML 5.99%

djaodjin-annotate's Introduction

#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="/static/css/djaodjin-annotate.css" />
</head>
<body>


	<script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
	<script type="text/javascript" src="/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:

  • Push an image with only path: (If image exists an id will be automatically created.)
$("#myCanvas").annotate("push", "images/test_2.jpg");
  • Push an image with and id and a path: (allow to build an image selector manually)
$("#myCanvas").annotate("push", {id:"unique_identifier", path: "images/test_2.jpg"});

Export image

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

Returns the image in Data URI format.

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

Events

  • annotate-image-added: Fired when an image is initialized (plugin initialization or when a new image is pushed). Can be used to build image selector.

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

  • Fix destroy method

###v0.0.3

  • Responsive annotation position
  • Reponsive line width and font size

###v0.0.2

  • Ability to destroy an annotate instance
  • work with multiple images
  • Ability add new image after initialization

###v0.0.1

  • bower release

#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.

djaodjin-annotate's People

Contributors

a-reda avatar pauljordaan avatar rob-in avatar smirolo avatar stephanerob avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.