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

Using v1, resize operation should preserve aspect ratio or it should resize to the set dimension? #93

Closed
nvartolomei opened this issue Jun 27, 2016 · 6 comments · May be fixed by #260
Closed

Comments

@nvartolomei
Copy link
Contributor

Looking at the code, looks like body, err = img.Process(bimg.Options{ Width: 1000, Height: 1000 }) should actually resize the image to a size contained by the box, preserving aspect ratio, or I understood something wrong?

It my case it actually resizes the image to the fixed 1000x1000px, is this the correct behavior and for the case described above I should do the calculations myself?

@h2non h2non added the question label Jun 27, 2016
@h2non
Copy link
Owner

h2non commented Jun 27, 2016

Try passing Crop: true field in bimg.Options.

@nvartolomei
Copy link
Contributor Author

nvartolomei commented Jun 27, 2016

So the ar thing (func imageCalculations) is related to cropping?

@h2non
Copy link
Owner

h2non commented Jun 28, 2016

You don't have to do manual crop calculation unless you explicitly want it. bimg crop calculus is based on a specific width, height or both. If you want to keep the aspect ratio, you should pass only width or height, since the other axis size will be implicitly based on the original image size, so aspect ratio should be maintained.

Is that clear for you? Try running some transformation.

@nvartolomei
Copy link
Contributor Author

My use case is that I want to use bimg to resize an image to fit in a box of 1024x1024, so if it's wider it would resize to something like 1024x800px and if it is taller to 800x1024px.

@h2non
Copy link
Owner

h2non commented Jun 28, 2016

Try using Crop: true and Enlarge: true with a specific ´Width´ or ´Height´. If you pass Force: true, the aspect ration won't be maintained.

@kevin1024
Copy link

I'm wondering about this as well. I would like my image to "fit in" a given box. I don't want anything cropped, just resized, preserving the aspect ratio. Resize does what I want if I only pass one dimension, but I want to pass both width and height.

Example: I have an image that is 100x200. I ask for it to "fit in" a box of 100x100. The image I get back should be 50x100.

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

Successfully merging a pull request may close this issue.

3 participants