resize-image
v0.1.0
Published
Resize images in browser using canvas
Downloads
3,733
Readme
resize-image
Resize images in browser using canvas
Install
npm
npm i resize-image --save
bower
bower install resize-image --save
Usage
var resizeImage = require('resize-image');
var img = new Image();
img.onload= function () {
var data = resizeImage.resize(img, 200, 100, resizeImage.PNG);
console.log(data);
};
img.src = url; // local image url
.resize2Canvas(img, width, height)
resize an <img>
or Image
or <canvas>
to canvas
- {Image} img: an
<img>
orImage()
- {number} [width]: output image width
- {number} [height]: output image height
.resize(img, width, height, type)
resize an <img>
or Image
or <canvas>
to base64
- {Image} img: an
<img>
orImage()
- {number} [width]: output image width
- {number} [height]: output image height
- {string} [type]: output image type
types
- .PNG (default)
- .GIF
- .BMP
- .JPEG
- .WEBP
Examples
yarn
npm run example
And visit http://localhost:9000/.