image-aspect-ratio

Image aspect ratio is a utility module which provides straight-forward, way to calculate aspect ratio of a image to fit within a given box.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
image-aspect-ratio
001.0.07 years ago7 years agoMinified + gzip package size for image-aspect-ratio in KB

Readme

image-aspect-ratio
Image aspect ratio is a utility module which provides straight-forward, way to calculate aspect ratio of a image to fit within a given box.

Installation

To install strong-password-generator, use npm:
npm install image-aspect-ratio

Usage

var imageAspectRatio = require("image-aspect-ratio");

imageAspectRatio.calculate(srcWidth, srcHeight, maxWidth, maxHeight);

example 01 : Calculation with Rectangle image with large width than height

var imageAspectRatio = require("image-aspect-ratio");

imageAspectRatio.calculate(1250, 580, 200, 200);
// >> {"width":200,"height":92.8}

example 02 : Calculation with Rectangle image with large height than width

var imageAspectRatio = require("image-aspect-ratio");

imageAspectRatio.calculate(580, 1250, 200, 200);
// >> {"width":92.8,"height":200}

example 03 : Calculation with Square image

var imageAspectRatio = require("image-aspect-ratio");

imageAspectRatio.calculate(1250, 1250, 200, 200);
// >> {"width":200,"height":200}

API

image-aspect-ratio.
  • calculate(srcWidth, srcHeight, maxWidth, maxHeight)
- srcWidth - width of the original image {Number} REQUIRED - srcHeight - height of the original image {Number} REQUIRED - maxWidth - maximum width of the box which wraps the image {Number} REQUIRED - maxHeight - maximum heigth of the box which wraps the image {Number} REQUIRED