lovell / lovell/sharp

Crop image using aspect ratio instead of dimensions

Open
#2,386 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

It would be great if there was a builtin function that allowed us to crop images based on aspect ratio instead of dimensions. The input to such a function could be the aspect ratio and (probably) a gravity. Basically, the function would calculate the largest possible dimensions based on the aspect ratio, the gravity would influence the starting point.

There was a similar feature request. However, it was solved for 1:1, but I need to crop a 9:16 image to 16:9.

Here's a sample of how the function would look like:
```
aspect(16 / 9, "centre")
```

I could create a PR implementing this function. Someone would have to guide me though. :sweat_smile:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation file or test. Start by locating sharp's existing crop/resize entry point and the prior 1:1 aspect-ratio feature mentioned here; confirm how a 16:9 crop and gravity should behave, then add coverage showing the requested aspect-ratio result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
computer-graphics
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.