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

Closed
wants to merge 2 commits into 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

@xenova
Copy link
Collaborator

xenova commented Nov 16, 2024

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

No worries - we will merge that one first 👍

As for this PR, could you also provide a reference to the function that is in another image processing library (e.g., PIL) which is similar? It's useful to align with existing libraries to make sure we don't stray too far away from python standards. Thanks!

@BritishWerewolf
Copy link
Contributor Author

Actually, I am going to close this PR.
I originally suggested it because I found myself needing it - despite it not being present elsewhere! - however I have not found myself using it since opening.
Thanks.

@BritishWerewolf BritishWerewolf deleted the pad-to-square branch November 17, 2024 00:50
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.

2 participants