coobird / thumbnailator

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

No suitable ImageReader found #163

Closed sunweihxh closed 3 years ago

sunweihxh commented 3 years ago

Expected behavior

got a exception:net.coobird.thumbnailator.tasks.UnsupportedFormatException: No suitable ImageReader found

Steps to reproduce the behavior

scale0_3 = new File(imagePath+File.separator+"scale0_3");

    scale0_6 = new File(imagePath+File.separator+"scale0_6");

    //Thumbnails.of(original).scale(0.3).toFile(scale0_3);
    //Thumbnails.of(original).scale(0.6).toFile(scale0_6);

    Thumbnails.of(original).scale(0.3).toOutputStream(new FileOutputStream(scale0_3));
    Thumbnails.of(original).scale(0.6).toOutputStream(new FileOutputStream(scale0_6));

Environment

jdk1.8 tomcat8.5

dmitry-weirdo commented 3 years ago

Good day @sunweihxh!

You should post:

Most probably your image either has an unsupported format or is broken. AFAIR I had some exceptions on jpeg files that have broken EXIF info or something alike. I re-saved it with a graphic editor, after it the thumbnailator worked. For HEIC files, I converted it to JPEG.

sunweihxh commented 3 years ago

Thank you for your reminding. I used version 0.4.8. My error details are as follows:

net.coobird.thumbnailator.tasks.UnsupportedFormatException: No suitable ImageReader found for d:\images\image\courseUserWork\2020-10-15\xIVSkZlYEeGYhpNuokqG\original. at net.coobird.thumbnailator.tasks.io.FileImageSource.read(FileImageSource.java:118) at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(SourceSinkThumbnailTask.java:76) at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Thumbnailator.java:53) at net.coobird.thumbnailator.Thumbnails$Builder.toOutputStream(Thumbnails.java:2737)

The picture I uploaded is

original1

coobird commented 3 years ago

@sunweihxh The file you uploaded is a WebP image. (Despite the "jpg" extension it wasn't a JPEG.)

Thumbnailator relies on the Java Image I/O API's image reading and writing facilities, which does not have support for WebP out-of-the-box. In order to use WebP, you'll need to find a compatible Image I/O plugin.

There appears to be some options for using WebP from Java Image I/O which you'll be able to find in a previously filed issue (#137) and in a comment I made here.

Once such a plugin is enabled, you should be able to use Thumbnailator without further modifications.

sunweihxh commented 3 years ago

@coobird @dmitry-weirdo thanks a lot.