Closed richiksc closed 4 years ago
Without going too much into detail, have you tried setting the image type to ARGB?
Thumbnails.of(image)
.size(128, 128)
.keepAspectRatio(true)
.outputFormat("png")
.imageType(ThumbnailParameter.DEFAULT_IMAGE_TYPE) // a.k.a. BufferedImage.TYPE_INT_ARGB
.toFile(file);
@richiksc As you've noticed, it happens for paletted 8-bit PNGs, and the solution posted by @rntrp solution would work.
This is actually a duplicate of #41 which happens for index-paletted transparent PNGs.
Expected behavior
Resize an image to a smaller size without greatly affecting the visual quality of it.
My source image is this:
and when I run it through Thumbnailator using
I expect it to come out as a 128x128 PNG image retaining its transparent background - the file is smaller and there may be some artifacting, but no major aberrations.
Actual behavior
The output image is this:
The logo has lost its transparent background for a black one and there are horrible red vertical 'scanlines' running through the orange part of the logo. For some reason, this issue only happens on this image and not the 5 other images I have ran through Thumbnailator. The only difference is that this source image is an 8bit png instead of a 24bit png.
Steps to reproduce the behavior
Run the above sample image through the provided Thumbnailator code..
Environment