Giter Site home page Giter Site logo

paint.js's Introduction

Installation

Download the zip file and place it in your project's folder, or you can use git clone instead of manual download. After you complete one of those steps, just import the paint.js file. Don't forget that paint.js requires jQuery.js and JSColor.js

<script type="text/javascript" src="paint.js/src/jscolor.js"></script>
<script type="text/javascript" src="paint.js/src/jquery.js"></script>
<script type="text/javascript" src="paint.js/src/paint.js"></script>

Usage

After you import the library, you can create a <div> element and use PaintJS object to initialize inside that div.

<div id="paint"></div>
...
<script type="text/javascript">
    var paint = new PaintJS({
        paint: "#paint" // or document.getElementById("paint")
    });
</script>

After user is done drawing, you can extract base64 contents using

completeButton.onclick = function() {
    var base64 = paint.canvas.toDataURL();
    // $.ajax(...) upload using the base64 content
}

Customization

you can initialize PaintJS object with custom options

var paint = new PaintJS({
    paint: "#paint", // required key
    brushSize: 35, // 8 is default
    brushColor: "#ff0000", //  hexadecimal value, default #000
    paletteColors: [ // array of color shortcut, so that user does not have to use colorpicker for everything
    "#ffffff",
    "#000000",
    "#808080"
    ]
});

Drawing on Images

you can initialize PaintJS to load from URL

var paint = new PaintJS({
    paint: "#paint"
});
paint.fromURL("test.jpg").then(function(paintJS) {
    // act on paintJS
}).catch(function(err) {
    // probably link is invalid
    console.log(err);
});

Creating brushes

var brush = new PaintJSBrush({
    icon: "icons/brush.png", // icon to display in brushes section, required
    brushIcon: "icons/circle.png", // icon which will be displayed while mouse has entered the canvas
    documentMousedown: function(e) { // optional. event is fired on canvas mousedown
        var x = e.x;
        var y = e.y;
        var paintJS = this.paintJS; // referrence to PaintJS object
        var canvas  = paintJS.canvas;
        var ctx     = paintJS.ctx;
        var size    = paintJS.brushSize;
        var color   = paintJS.brushColor;
        ...
    }
    
});

var paint = new PaintJS({
    paint: "#paint",
    brush: brush // this will add this brush to initial brushes, and set it as active
});

Todo

  • Add support for transparency
  • Add support for setting brushes and colors instead of only adding them
  • Make selecting tool
  • Undo and Redo

Contributions are VERY welcome!

paint.js's People

Contributors

khokho avatar

Watchers

James Cloos 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.