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 pad an image to a square #972

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from

Conversation

BritishWerewolf
Copy link
Contributor

This PR is stacked on PR 971.
On my fork, this was branched off the other PR, but I couldn't find a way to do this with PRs - sorry 😅


It's common to want to create a square image, currently we need to do some manual calculations.

With this PR, we can do something like this, with no arguments to just fill the blank area.

const image = await RawImage.fromURL("https://picsum.photos/600/400");
const resized = await image.resize(300, null); // 300x200
const padded = await resized.padToSquare();    // 300x300

Or we can provide a value, and make the image pad to that size.

const image = await RawImage.fromURL("https://picsum.photos/600/400");
const resized = await image.resize(300, null); // 300x200
const padded = await resized.padToSquare(400); // 400x400

Providing a value that is smaller than either the width or height will just return the image unchanged.

const image = await RawImage.fromURL("https://picsum.photos/600/400");
const resized = await image.resize(300, null); // 300x200
const padded = await resized.padToSquare(100); // 300x200

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