liyiguang / thumbnailator

Automatically exported from code.google.com/p/thumbnailator
Other
0 stars 0 forks source link

Output quality don't work with "asBufferedImage" #53

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create new thumbnail using 
Thumbnails.of(image)
                .size(500,500)
                .scalingMode(scalingMode)
                .outputQuality(0.1f)
                .asBufferedImage();
2. Create file using this bufferedImage
3. Quality is not changed
ACTUAL RESULT: quality is not changed (quality is same as original image)
EXPECTED RESULT: Quliaty is set to 10%

What version of the product are you using? On what operating system? Which
version of Java (Sun/Oracle? OpenJDK?) ?
JDK 1.7 (tried also on 1.6), Version of Thumbnailator is 0.8

Original issue reported on code.google.com by marek.kr...@fullsix.com on 27 Aug 2013 at 12:49

GoogleCodeExporter commented 9 years ago
Thank you for filing this issue.

The `outputQuality` method is used to specify the output quality of the 
*compression algorithm when writing to a file or output stream*.

Therefore, using `outputQuality` when the output is a `BufferedImage` does not 
affect the final output.

I have clarified this behavior in the documentation for the `outputFormat` and 
`outputQuality` methods.

-> It should be noted that the `BufferedImage` object does not have a property 
to mark what output quality should be used when it is written to an image. As a 
result, the output quality will not change.

In order for `outputQuality` to actually change the compression quality of the 
final thumbnail, one must use one of the methods that outputs to a `File` or 
`OutputStream`.

For example:

  Thumbnails.of("path/to/image.jpg")
    .size(100, 100)
    .outputQuality(0.8)
    .toFile("path/to/thumbnail.jpg");

The above code will set the JPEG output quality to 0.8 when writing the JPEG 
image.

Original comment by coobird...@gmail.com on 3 Sep 2013 at 4:13