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

Resize image to square (1:1 ratio) while retaining original image aspect ratio #3083

Open
kewlb0t opened this issue Jan 30, 2025 · 4 comments

Comments

@kewlb0t
Copy link

kewlb0t commented Jan 30, 2025

I've been trying to get a specific resize result using chaiNNer but I'm having trouble making it work.

I've left an example of what I'm trying to accomplish in the attachment

Image

Any help is appreciated.

@joeyballentine
Copy link
Member

Use the math node to get the maximum value of the height and width, which you can get using the get dimensions node. Then use another math node to get the difference between each dimension and its max, then the pad node to pad each dimension with the result. That should do it

There may be a better way to do this but at least that'll work

@joeyballentine
Copy link
Member

joeyballentine commented Jan 30, 2025

That would be after a regular resize of course -- for that the easiest way would be using the resize to side node if you want the largest dimension to become 458 no matter which side

@kewlb0t
Copy link
Author

kewlb0t commented Jan 30, 2025

Use the math node to get the maximum value of the height and width, which you can get using the get dimensions node. Then use another math node to get the difference between each dimension and its max, then the pad node to pad each dimension with the result. That should do it

There may be a better way to do this but at least that'll work

Hey Joey, thanks for the help. Just want to make sure I'm doing this correctly.
For the second step, do you mean I'm subtracting both the height and the width each from the max?
Here's how my nodes are set up for reference:

Image

@kewlb0t
Copy link
Author

kewlb0t commented Jan 31, 2025

I know this specific use case might not be useful for most people who use this application but I think this could potentially help some people who use chaiNNer for work tasks. I work in e-commerce and chaiNNer is really useful for cleaning up product images, I just wish there was an option to keep the image aspect ratio the same when scaling 1:1.

Image

Imageresizer.com has this great option that lets you unlock the aspect ratio and let's you scale the image however you like without causing the image to be deformed. There's also an option to fill the alpha channel with a color when converting a PNG to something like JPG. I could just use this website for my images, but I feel like chaiNNer is a lot faster and works best with my workflow. I think these could potentially be useful features for chaiNNer in the future.

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

No branches or pull requests

2 participants