coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.14k stars 784 forks source link

The image becomes larger after compression #171

Closed goooong closed 3 years ago

goooong commented 3 years ago

code: File file = new File("bailu.jpg"); Thumbnails.of(file).outputQuality(0.9d).scale(1d).toFile("bailu2.jpg");

before size :73kb after size :76kb

goooong commented 3 years ago

before: bailu after: bailu2

coobird commented 3 years ago

File sizes increasing for the same size image is completely expected when using JPEG.

There can be a couple of reasons for this -- first, if the original JPEG is using a lower quality setting (i.e. lower compression quality) the resulting image can be a larger file size. Second reason, even if the original image and the resulting image both were using the same quality setting, saving a JPEG again as a JPEG can lead to lower compression ratios, hence larger file sizes. And the resulting image will be likely less visual quality than the original. These two effects are due to the nature of JPEG compression.

This is not an issue with Thumbnailator, but a general nature of using JPEG image compression.

goooong commented 3 years ago

File sizes increasing for the same size image is completely expected when using JPEG.

There can be a couple of reasons for this -- first, if the original JPEG is using a lower quality setting (i.e. lower compression quality) the resulting image can be a larger file size. Second reason, even if the original image and the resulting image both were using the same quality setting, saving a JPEG again as a JPEG can lead to lower compression ratios, hence larger file sizes. And the resulting image will be likely less visual quality than the original. These two effects are due to the nature of JPEG compression.

This is not an issue with Thumbnailator, but a general nature of using JPEG image compression.

thank you.

micMalloc commented 3 years ago

@coobird Hello, I'm Heesu. I would like to ask if it is the same for PNG. Thanks.

Thumbnails.of(input).scale(1.0f).outputQuality(0.85f).toFile("/Users/we/Desktop/output.png");

Before size: 18122 After size: 279584

[input image] input

[output image] output