object_painter

1.0.0 • Public • Published

object_painter

object_painter is an open source project made with javascript that allows an application to paint an object image in different layers with canvas.

Designed for

Websites and applications who wants to deliver better experiences for your customers and any project that wants to implement an environment painter with a simple way to integrate using an easy api for that.

Features

  • Loads a environment image
  • Add Layer mask to proccess object colors
  • Set fit mode to adapt the image on canvas
  • Set layer color to paint object
  • Get layer colors data
  • Get a specific layer color
  • Reset colors and fit

Installation

This is a pure javascript library available through the npm registry and no dependency is required.

$ npm install object_painter

To test the lib you must to have a local server like http://localhost because canvas check the CORS from image file data, so you can try:

$ npx http-server -c-1 -a localhost -p 8000 

Usage

<canvas width="400" height="300" id="room"></canvas>
<script src="node_modules/object_painter/src/object_painter.js"></script>
<script>
    const objectPainter = new ObjectPainter({
        canvasId: "room",
        fit: "stretch"
    });
    objectPainter.loadBackground('path/to/yours/image.jpg')
    objectPainter.addLayer('layer_name', 'path/to/yours/mask.png')
</script> 

To have a great experience, your masks must have the same size of your original loaded image as background.

API

  • Before call any function, be sure to create an instance of library:
    const objectPainter = new ObjectPainter({
        //The canvas identifier
        canvasId: "room",        
        //The image size adapter
        fit: "stretch",
    });
  • Loading a environment image as background:
    objectPainter.loadBackground('path/to/yours/environment.png')
  • Loading a mask image to proccess colors:
    objectPainter.addLayer('layer_name','path/to/yours/mask.png')
  • Setting the paint color to a specific layer:
    objectPainter.setLayerColor('layer_name', "red")
  • Setting the fit image adaptation to deliver a good experience:
    objectPainter.setFit("stretch") //stretch, contain, cover
  • Get a specific layer painted color:
    objectPainter.getLayerColor("layer_name")
  • Get all layer painted colors:
    objectPainter.getColors()
  • Remove all painted colors:
    objectPainter.reset()

License

MIT

Package Sidebar

Install

npm i object_painter

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

20.7 MB

Total Files

10

Last publish

Collaborators

  • andreciornavei