Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the thumbnailator support generating thumbnails for png images? #214

Closed
lhfwudi opened this issue Dec 4, 2023 · 1 comment
Closed

Comments

@lhfwudi
Copy link

lhfwudi commented Dec 4, 2023

Why do png thumbnails report exceptions?

  1. My code is as follows
    public static void main(String[] args) throws Exception {
    String srcFile = "C:\Users\admin\Desktop\2222.png";
    String desFile = "C:\data1\share\biztable\mini\task_fill\333.png";
    BufferedImage originalImage = ImageIO.read(new File(srcFile));
    BufferedImage thumbnail = Thumbnails.of(originalImage)
    .size(200, 200)
    .keepAspectRatio(false)
    .asBufferedImage();
    Thumbnails.of(thumbnail)
    .scale(0.3)
    .outputQuality(0.25f)
    .toFile(desFile);
    }
  2. The abnormal information is as follows
    Exception in thread "main" javax.imageio.IIOException: Unsupported Image Type
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1079)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1050)
    at javax.imageio.ImageIO.read(ImageIO.java:1448)
    at javax.imageio.ImageIO.read(ImageIO.java:1308)
    at zsoft.gov.datacenter.biztable.common.utils.UploadUtil.main(UploadUtil.java:266)

May I ask what causes it? Or is the thumbnailator not supported?

@coobird
Copy link
Owner

coobird commented Dec 16, 2023

@lhfwudi, the stacktrace shows that Thumbnailator is not being called. The exception is happening on this line:

BufferedImage originalImage = ImageIO.read(new File(srcFile));

And inspecting closer, Java thinks it's a JPEG file even though it has a PNG extension. Therefore, it seems like your image file is mislabeled with a wrong extension. This is not an issue with Thumbnailator as it's not being invoked.

@coobird coobird closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants