Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to maintain aspect ratio on resize #971

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from

Conversation

BritishWerewolf
Copy link
Contributor

In some cases it is required to resize an image, but maintain the aspect ratio.
This is usually because we want to pad the image.

Here's an example of something I was thinking of.

const image = await RawImage.fromURL("https://picsum.photos/600/400");
const resized = await image.resize(300, null); // 300x200
const padHeight = (300 - image.height) / 2;
const padded = await image.pad([0, 0, padHeight, padHeight]); // 300x300

In this example, we resize the image, maintain the aspect ratio and then pad either side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant