Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanhefner/calculate-aspect-ratio
π A simple utility function, and command line utility, for calculating an aspect ratio based on width and height.
https://github.com/ryanhefner/calculate-aspect-ratio
aspect-ratio calculate calculate-aspect-ratio command-line-tool javascript npm-module utility
Last synced: 3 months ago
JSON representation
π A simple utility function, and command line utility, for calculating an aspect ratio based on width and height.
- Host: GitHub
- URL: https://github.com/ryanhefner/calculate-aspect-ratio
- Owner: ryanhefner
- License: mit
- Created: 2017-10-06T04:38:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-08T16:52:50.000Z (about 7 years ago)
- Last Synced: 2024-11-01T12:35:47.756Z (3 months ago)
- Topics: aspect-ratio, calculate, calculate-aspect-ratio, command-line-tool, javascript, npm-module, utility
- Language: JavaScript
- Homepage: https://aspectrat.io
- Size: 27.3 KB
- Stars: 45
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π calculate-aspect-ratio
A simple utility function, and command line utility, for calculating an aspect
ratio based on `width` and `height`.## Install
Via [NPM](https://npmjs.com/packages/calculate-aspect-ratio)
```sh
npm install --save calculate-aspect-ratio
```Via [Yarn](https://yarn.fyi/calculate-aspect-ratio)
```sh
yarn add calculate-aspect-ratio
```CLI
```sh
npm install -g calculate-aspect-ratio
```## How to use
There are two ways you can use this module. You can use it directly in your
Javascript by importing it and calculating various aspect ratios where you need them.Iβve also included a handy command line utility that you can use to determine the
aspect ratio by calling it and providing a `width` and `height`.### Import
The import is useful in scenarios where you need to calculate the aspect ratio
when you have access to an assets `width` and `height`.Iβm currently using this to determine the aspect ratio of videos accessed via a
CMS and passing the aspect ratio to [`react-video-players`](https://github.com/ryanhefner/react-video-players)
so they scale nicely in fluid layouts.```js
import calculateAspectRatios from 'calculate-aspect-ratio';
```In addition to the method used to calculate the aspect ratio, Iβve also exposed
the method used to get the greatest common divisor. You can access that via the
`gcd` export.```js
import { gcd } from 'calculate-aspect-ratio';
```#### Example
```js
import calculateAspectRatio from 'calculate-aspect-ratio';const aspectRatio = calculateAspectRatio(2880, 1800); // '8:5'
```### CLI
A simple utility command that you can run via the command line to return the
aspect ratio for a provided `width` and `height`.```sh
$ aspectratio [options] [width] [height]
```#### Options
| Option | Description |
| ------------------- | ------------------------- |
| `-V`, `--version` | output the version number |
| `-h`, `--help` | output usage information |#### Arguments
| Argument | Type | Default |
| ------------------- | ----------- | ----------- |
| `width` | Number | `1920` |
| `height` | Number | `1080` |#### Example
```sh
$ aspectratio 2880 1800 // Output -> Aspect ratio: 8:5```
## Need an easy way to calculate aspect ratios?
After making `calculate-aspect-ratio`, I realized that in addition to the CLI
tool, it might be nice to make a site that makes it easy for non-developers βΒ
and developers alike βΒ to review and calculate various aspect ratios, as well
as reference common device resolutions. So, I made a handy tool that does just
that, offering a visual way to calculate and reference aspect ratios. I hope
you find it usefulπCheck out: [https://aspectrat.io](https://aspectrat.io)
## License
[MIT](LICENSE) Β© [Ryan Hefner](https://www.ryanhefner.com)