image-data-resizer
v0.1.0
Published
A one-line-ish module to resize canvas images keeping aspect ratio
Downloads
2
Readme
image-data-resizer
Install globally with npm
$ npm i -g image-data-resizer
What is it
Computes rescaling coordinates (padding and new size) of an image to be put into a canvas, by keeping aspect ratio.
E.g., compute vertical padding of wide figures:
// Canvas Dimensions (width and height)
var cd = {
cw: 100,
ch: 100
};
// Pass in Dimensions (iw = image width, ih = image height)
computeAllPosAndSizeNoFit({
iw: 400,
ih: 100
}, cd)
//You get:
//
//{
// dx: 0, <- h padding
// dy: 37.5, <- v padding
// scaleh: 0.25,
// scalew: 0.25,
// nw: 100, <- new width
// nh: 25 <- new height
//}
API
fitHeight()
reduces height and width
fitWidth()
reduces width and height
Author
- Vittorio Zaccaria
License
Copyright © 2015 Vittorio Zaccaria Released under the BSD license.
This file was generated by verb-cli on October 24, 2015.