Skip to content

Independently specify the scaling factors for width and height #19

@GoogleCodeExporter

Description

@GoogleCodeExporter
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions