https://github.com/spencermountain/crop-aspect
crop an image by a nearby aspect-ratio
https://github.com/spencermountain/crop-aspect
Last synced: 18 days ago
JSON representation
crop an image by a nearby aspect-ratio
- Host: GitHub
- URL: https://github.com/spencermountain/crop-aspect
- Owner: spencermountain
- Created: 2019-01-23T18:52:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-01T23:32:20.000Z (almost 3 years ago)
- Last Synced: 2025-03-21T11:16:23.837Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 62.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
npm i -g crop-aspect
here's an image of an Apollo guidance computer:

#### it's **500x391px**.
this is a ratio of `1:0.782` *(or `4:2.346`)*
that is *almost* `4:3`, which is one of the most-commonly used aspect ratios ever.
This is a nodejs CLI script that chops-off a bit of the image, so that it fit's a nearby aspect ratio.
```
crop-aspect ./apolloComputer.jpg
```this creates a file, `./apolloComputer-500.jpg`
that is **500x375px**.this also works:
```
crop-aspect ./myImg.jpg 16:9
crop-aspect ./myImg.jpg golden
```you can also call it from node:
```js
var cropAspect=require('crop-aspect')
cropAspect('./myImg.jpg','square').then(()=>{
console.log('done!')
})
```[sharp](https://sharp.pixelplumbing.com) is doing all the heavy-lifting. This library is simply placing some opinionated aspect-ratios on top of it.
i mean, davinci thought math-sizes were nicer, so I figure ... well, i don't know.
it's using [fit-aspect-ratio](https://github.com/spencermountain/fit-aspect-ratio/) for the maths
work-in-progress
MIT