Image aspect ratio utilities.
npm install aspectratio --save
var aspect = require('aspectratio');
width
, integer height
, string ratio
)Apply a fixed aspect ratio
crop without distoring the image aspect ratio.
width
- original image widthheight
- original image heightratio
- new image ratioThe
ratio
must be on the following format:x
:y
wherex
andy
are integers. The order ofx
andz
does not matter and3:4
will be treated as4:3
.By default #crop() will match the orientation of the original image unless a forced orientation is given on the follwing format:
x
:y
!z
wherez
is the orientation (v
for vertical, orh
for horizontal).
This will return an Array
of four values:
x
- top lef x coordinatey
- top lef y coordinatewidth
- new image widthheight
- new image heightvar crop = aspect.crop(2048, 768, '4:3');
// [512, 768, 1024, 768]
x
, integer y
, integer maxX
, integer maxY
)Get resized height and width of an image while perserving the aspect ratio of the image.
x
- original image widthy
- original image heightmaxX
- max image widthmaxY
- max image heightReturns an Array
of the resized x
and y
values:
x
- resized image widthy
- resized image height