coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.08k stars 780 forks source link

Require explicitly setting image type when outputting to BufferedImage(s) #192

Open coobird opened 2 years ago

coobird commented 2 years ago

Currently, Thumbnailator does not require setting the BufferedImage type and will (attempt to) use the types as the input source. (More specifically, the image type that is used by the Image I/O ImageReader implementation used for the image.) This means that the type can differ depending on the image type or the image itself.

By requiring the output type to be a certain type, the inconsistencies can be eliminated and also could avoid issues like "wrong colors in JPEG" issue that stems from handing a BufferedImage with an alpha channel to the default JPEG writer shipped with Java.

Also consider limiting the use of imageType method to only use with methods that output BufferedImage(s) like asBufferedImage.