All Projects → ryanhefner → calculate-aspect-ratio

ryanhefner / calculate-aspect-ratio

Licence: MIT license
📐 A simple utility function, and command line utility, for calculating an aspect ratio based on width and height.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to calculate-aspect-ratio

Tspath
TypeScript path alias resolver
Stars: ✭ 115 (+167.44%)
Mutual labels:  utility, npm-module
json-as-xlsx
Create excel from json npm package
Stars: ✭ 103 (+139.53%)
Mutual labels:  npm-module
Pareto.js
An extremely small, intuitive and fast functional utility library for JavaScript
Stars: ✭ 254 (+490.7%)
Mutual labels:  utility
chrome-extension-aspectratio219
🖥️ Fit the screen properly in fullscreen mode on monitor ultrawide with 21:9 aspect ratio (Netflix, Youtube, PrimeVideo, Crunchyroll)
Stars: ✭ 28 (-34.88%)
Mutual labels:  aspect-ratio
ifto
A simple debugging module for AWS Lambda (λ) timeout
Stars: ✭ 72 (+67.44%)
Mutual labels:  npm-module
WinDev-Utility
A utility for windows developers
Stars: ✭ 17 (-60.47%)
Mutual labels:  utility
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+6460.47%)
Mutual labels:  utility
GPUUtilization
measure GPU hardware utilization on iOS Devices
Stars: ✭ 102 (+137.21%)
Mutual labels:  utility
toastify
🍞A commandline tool that shows desktop notifications using notify-rust
Stars: ✭ 60 (+39.53%)
Mutual labels:  utility
superglue
A productive library for Classic Rails, React and Redux
Stars: ✭ 106 (+146.51%)
Mutual labels:  npm-module
windows-registry-node
Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and other goodies.
Stars: ✭ 105 (+144.19%)
Mutual labels:  npm-module
fetch-action-creator
Fetches using standardized, four-part asynchronous actions for redux-thunk.
Stars: ✭ 28 (-34.88%)
Mutual labels:  npm-module
unity-scene-view-copier
Makes positioning Cameras in Unity much easier. 🎥
Stars: ✭ 22 (-48.84%)
Mutual labels:  utility
pwainit
Turn your existing website to Progressive Web App or Initiate PWA project using single command!!. 'npm i -g pwainit' to install pwainit and get started 🚀
Stars: ✭ 45 (+4.65%)
Mutual labels:  npm-module
apint
Arbitrary precision integers library.
Stars: ✭ 23 (-46.51%)
Mutual labels:  utility
Musoq
Use SQL on various data sources
Stars: ✭ 252 (+486.05%)
Mutual labels:  utility
eslint-plugin-gridsome
ESLint plugin for Gridsome
Stars: ✭ 45 (+4.65%)
Mutual labels:  npm-module
extension-generator
This package is no longer supported. Please use https://github.com/flarum/cli instead.
Stars: ✭ 53 (+23.26%)
Mutual labels:  npm-module
react-pendulum
A React Context utility library.
Stars: ✭ 15 (-65.12%)
Mutual labels:  utility
gendesk
🌿 Generate .desktop files and download .png icons by specifying a minimum of information
Stars: ✭ 101 (+134.88%)
Mutual labels:  utility

📐 calculate-aspect-ratio

A simple utility function, and command line utility, for calculating an aspect ratio based on width and height.

Install

Via NPM

npm install --save calculate-aspect-ratio

Via Yarn

yarn add calculate-aspect-ratio

CLI

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 so they scale nicely in fluid layouts.

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.

import { gcd } from 'calculate-aspect-ratio';

Example

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.

$ 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

$ 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

License

MIT © Ryan Hefner

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].