gigaZhang / thumbnailator

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

Resizing 8-bit PNG produces poor quality result. #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. original.png is a 128x128 8-bit paletted PNG.
2.
Builder<? extends InputStream> thumbnailBuilder = Thumbnails.of(new 
FileInputStream("original.png");
thumbnailBuilder.size(80, 80);
thumbnailBuilder.toOutputStream(new FileOutputStream("resized in 
thumbnailator.png"));

What is the expected output? What do you see instead?

I expect a decent resize result, like 'resized in editor.png' (I used Corel 
Photo Paint 12, which retained the 8-bit color depth in the result). Instead I 
see an image with poor color interpolation. Setting the alpaInterpolation, 
antialiasing, dithering, rendering, resizer and scalingMode to the quality 
modes or any of the interpolation algorithms didn't produce a result like the 
one using my editor. 

What version of the product are you using?
0.3.10

On what operating system?
Ubuntu 10

Which version of Java?
JDK 6

Original issue reported on code.google.com by will.t...@xtremelabs.com on 16 Nov 2011 at 3:41

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for the detailed report.

I'll have to take a closer look at where the image is becoming unsatisfactory, 
and if there are any workarounds which can be put in place to improve image 
quality.

There are two places that I can think of at the moment that can be causing 
problems.

1. The image resizing step -- perhaps increasing the color depth from 8-bit to 
a 32-bit ARGB (or 24-bit RGB) may improve the result.

2. The image encoding step -- it's possible that even feeding a 24-bit image 
into the PNG encoder (the default which comes with the Java runtime) may result 
in a poor image. There may be settings to improve the downsampling that I 
haven't taken a look at yet.

I'll have to investigate further to see if there's anything that can be done to 
improve the image quality of the resulting thumbnail.

Once again, thank you for reporting this issue.

Original comment by coobird...@gmail.com on 26 Nov 2011 at 8:17

GoogleCodeExporter commented 9 years ago
Sorry for the delay in the follow-up.

There is a workaround to this issue, as long as the resulting PNG can be a 
24-bit image (with transparency):

  Thumbnails.of("original.png")
    .size(80, 80)
    .imageType(BufferedImage.TYPE_INT_ARGB)
    .toFile("thumbnail.png");

The `imageType` method can be used to specify the thumbnail's image type. In 
the above code, the output format will be a 24-bit RGB image with a 
transparency channel.

The catch is that the resulting thumbnail will have a file size that is larger 
than the original, and the bit-depth will no longer be 8-bit.

If there is a requirement to keep the thumbnail as a 8-bit image, then the 
internals of Thumbnailator will have to be modified.

Original comment by coobird...@gmail.com on 26 Feb 2012 at 6:59

GoogleCodeExporter commented 9 years ago
I have similar problem. Reading png, resizing and then saving as jpg. Result 
are also very pure.

Original comment by marcin.m...@gmail.com on 5 Mar 2012 at 12:48

GoogleCodeExporter commented 9 years ago
Very bad output on PNG resizing, basically useless.. I'm going to have to 
either switch everything to JPG or find something else.

Original comment by ottersl...@gmail.com on 30 Nov 2014 at 7:12