regioned-image
Breaks an image into regions of contiguous pixels. You can set the colors and boundaries of regioned images and render them to a canvas.
Setup
Install the package.
npm install regioned-image --save
Require the module.
var RegionedImage = ;
Note: RegionedImage needs to run a browser context. You can use something like browserify to bundle RegionedImage as a dependency. Take a look at the example if you need help with this.
Usage
You can specify a different width and height for the image at initialization:
var image = "france.svg" width: 300 height: 200;
The aspect ratio of the image will be preserved. This means that the image may be smaller than the width and height specified.
Serialization
Once the image has loaded, you can serialize your regioned image to json:
var image = "france.svg";var json; image { image; json = image;}; var clone = RegionedImage;console; // 1
Touch events
You can register a touch listener for the regioned image. It will be given the relative coordinates of the touch:
var image = "france.svg";var canvas = document; image { image;}; image { var region = image; regioncolor = "#FFFF00"; image;};
Reset
You can reset all region colors and boundary colors with the #reset method.
Note: If regions of different colors have been merged, it will reset to the original color of the merging region, which may not be the same as the original image.
Screenshot
Contribution
Please send a pull request or open an issue.
You should follow me on twitter.