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

Independently specify the scaling factors for width and height #19

Closed
GoogleCodeExporter opened this issue Jul 25, 2015 · 9 comments
Closed

Comments

@GoogleCodeExporter
Copy link

Per request from a user, add a new `scale` method overload to specify the 
scaling factor of the width and height independently, i.e.

  Thumbnails.of("path/to/image")
    .scale(0.6, 0.4)
    .toFile("path/to/thumbnail");

In the above code, the width will be scaled by 0.6 times, and height will be 
scaled by 0.4 times.

For example, a source image with dimensions 100 x 100 will result in a 
thumbnail that is 60 x 40. (The resulting image will not maintain the aspect 
ratio of the original.)


Background
---------------

Currently, rescaling an image by a scaling factor will maintain the aspect 
ratio of the width and height.

  Thumbnails.of("path/to/image")
    .scale(0.5)
    .toFile("path/to/thumbnail");

In the above code, if the source image is 100 x 100, the resulting image will 
be 50 x 50.

If one wants to rescale the width to 0.5 and height to 0.6, there is no simple 
one-liner that can be performed with Thumbnailator -- one would have to 
calculate the thumbnail size for each source image, and use one of the `size` 
methods to specify the final image size.


API Design Consideration
-------------------------

This new `scale` method will not maintain the aspect ratio of the original 
image unless the scaling factor for the width and height are equal. Therefore, 
unless the two factors are equal, calling the `keepAspectRatio` method should 
result in an `IllegalStateException`.

Original issue reported on code.google.com by coobird...@gmail.com on 13 Aug 2011 at 3:22

@GoogleCodeExporter
Copy link
Author

Work on this issue has started and should be part of the Thumbnailator 0.3.10 
release.

Original comment by coobird...@gmail.com on 28 Aug 2011 at 3:25

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Original comment by coobird...@gmail.com on 28 Aug 2011 at 3:33

  • Added labels: Milestone-0.3.10

@GoogleCodeExporter
Copy link
Author

When is 0.3.10 set to be released?

Original comment by littleki...@gmail.com on 29 Aug 2011 at 7:31

@GoogleCodeExporter
Copy link
Author

I hope to get Thumbnailator 0.3.10 out on September 3rd or 4th.

Original comment by coobird...@gmail.com on 1 Sep 2011 at 3:49

@GoogleCodeExporter
Copy link
Author

This feature has been implemented in Thumbnailator 0.3.10.

The new `scale(double, double)` method can be used to specify the scaling 
factors for the width and height independently.
http://thumbnailator.googlecode.com/hg/javadoc/net/coobird/thumbnailator/Thumbna
ils.Builder.html?r=0.3.10#scale%28double,%20double%29

Original comment by coobird...@gmail.com on 4 Sep 2011 at 3:03

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Awesome! I'll check it out tomorrow! Thanks

Original comment by littleki...@gmail.com on 7 Sep 2011 at 5:14

@GoogleCodeExporter
Copy link
Author

Never mind I was running two passes on these graphics first down to .66 and
then again to my target size I discovered if I just do it once the graphics
are very smooth not sure why two passes make it so janky. I'll just skip
the first step and do it one. Why two steps? My artist sent me some of the
graphics larger than our largest format. Thanks anyways.

Original comment by littleki...@gmail.com on 4 Nov 2011 at 4:26

@GoogleCodeExporter
Copy link
Author

Thank you for the follow up and glad things are working out.

Regarding the images not being smooth when resizing on two steps, I reproduced 
the problem you were having when scaling at 0.66, so I've opened a new issue. 
(Issue 25)

Once again, thank you for your valuable feedback.

Original comment by coobird...@gmail.com on 13 Nov 2011 at 6:15

@GoogleCodeExporter
Copy link
Author

You are welcome, I keep using it for all sorts of stuff, recently used it
for what it was meant for thumbnails for our website lol!

Original comment by littleki...@gmail.com on 13 Nov 2011 at 8:03

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

No branches or pull requests

1 participant