tiny-canvas-image-scaler

1.0.0 • Public • Published

Tiny Canvas Image Scaler Build Status NPM version

The purpose of this library is to be the smallest canvas-based image-scaling utility.

Usage

var imageScaler = require('tiny-canvas-image-scaler')
var options = {
  maxWidth: 300
};
 
imageScaler.getScaledUrl(imageUrl, options).then((scaledUrl) => {
  const image = document.getElementById('my_image');
  image.src = scaledUrl;
});
var imageScaler = require('tiny-canvas-image-scaler')
var options = {
  maxWidth: 200
};
 
imageScaler.getScaledCanvas(imageUrl, options).then((canvas) => {
  const container = document.getElementById('container');
  container.appendChild(canvas);
});

Options:

  • width - to scale to (height will adjust proportionally)
  • canvas - canvas DOM node that will be used to perform the scaling (one will be created, if not provided)
  • imageSmoothingEnabled - property of the canvas context
  • imageSmoothingQuality - property of the canvas context
  • imageFormat - String, .toDataURL(imageFormat), defaults to image/png
  • imageQuality - Number, .toDataURL(imageFormat, imageQuality), defaults to 0.92

Browser Support

All evergreen browsers plus IE11.

License

Apache-2.0

Readme

Keywords

Package Sidebar

Install

npm i tiny-canvas-image-scaler

Weekly Downloads

7

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • nemtsov