Cool library that let's you save your canvas as a png image on desktop and mobile. It also provides cropping options.
Cool library that let's you save your canvas as a png image on desktop and mobile. It also provides cropping options.
For mobile compatibility you need Cordova and Canvas2ImagePlugin as dependencies.
bower install canvas-image-saver --save
<script src="bower_components/canvas-image-saver/dist/canvasImageSaver.min.js"></script>
npm install canvas-image-saver --save
var CanvasImageSaver = require('canvas-image-saver');
canvas
: The canvas HTML5 element you want to save as image.cropOptions
: Optional.
successCallback
: Optional.
errorCallback
Optional.
callbackContext
Optional.
xCropOffset
: Optional. The x coordinate where to start clipping.yCropOffset
: Optional. The y coordinate where to start clipping.width
: Optional. The width of the clipped image.height
: Optional. The height of the clipped image.var canvasImageSaver = new CanvasImageSaver(
this.game.canvas, {
xCropOffset: 180,
yCropOffset: 0,
width: 470,
height: this.game.height
}, function (canvas) {
// Success callback
}, function () {
// Error callback
}, this);
canvasImageSaver.save();
TODO: Refactor using Q promises