resize-logic
Determines the correct dimensions for resizing and cropping images, without being attached to any particular tool
Usage
results = resize(options)
require('resize-logic')
exports a function that takes a selection of options:
var resize =var options =height: 200original: 400 200crop: truevar results =
options.original
: the original dimensions of the image as an array, i.e.:[width, height]
options.width
: the target width of the resized image. Optional, but one ofheight
orwidth
must be included.options.height
: the target height of the resized image. Optional, but one ofheight
orwidth
must be included.options.crop
: whether or not to crop the image or just scale it. Defaults tofalse
.options.smaller
: whether to scale to handle the smallest of width/height or heighest, when both are supplied. Defaults totrue
, orfalse
ifoptions.crop
is enabled.
When called, the function returns a results object with the following properties:
"drawPosition": -20 0"drawDimensions": 400 200"canvasDimensions": 360 200
results.drawPosition
The x/y position to draw the image (where the origin is the top-left). Supplied
as an array, i.e. [x, y]
.
results.drawDimensions
The width and height to draw the image. Supplied as an array, i.e.
[width, height]
.
results.canvasDimensions
The width and height of the actual canvas to draw on. Supplied as an array,
i.e. [width, height]
License
MIT. See LICENSE.md for details.