coobird / thumbnailator

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

300dpi tiff image changed to 96pi jpg but pixel does not chage #206

Closed liuyi520123 closed 10 months ago

liuyi520123 commented 1 year ago

Expected behavior

300dpi tiff image when change to jpg keep dpi and pixel

Actual behavior

tiff dpi=300dpi pixel=1181 x 1181 image convert to jpg dpi=96dpi pixel=1181 x 1181

Steps to reproduce the behavior

BufferedImage tif = ImageIO.read(new File("D:\\868602602.tif")); Thumbnails .of(tif) .outputFormat("jpg") .scale(1f) .outputQuality(1f) .toFile(new File("D:\\868602602.jpg"));

Environment

coobird commented 10 months ago

Sorry for overlooking this issue.

The dots-per-inch (DPI) information is metadata that's kept in certain file formats to instruct how an image should be printed. It doesn't actually affect the contents of the image file itself (i.e., the pixels.)

As Thumbnailator deals with the dimensions in pixels only, setting the scaling to 1x (i.e. .scale(1f)) will end up with the same number of pixels before and after the transformation. This is intended behavior.