coobird / thumbnailator

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

the image format webp is not support #203

Closed zhaohui90-lee closed 1 year ago

zhaohui90-lee commented 1 year ago

Expected behavior

Please describe what you are expecting the library to perform. When I used your project to upload webp format images to the server, I found that it did not support this format; But other formats such as jpg and png are fine. Here is a portion of the code for my project:

`File dest = new File(finalPath);

    // 判断文件父目录是否存在
    if (!dest.getParentFile().exists()) {
        boolean res = dest.getParentFile().mkdirs();
    }
    // 上传文件到服务器,相当于将内存的文件输出到服务器,OutputStream,需要try....catch....
    try {
        // 保存文件
        // transferTo(dest)方法将上传文件写到服务器上指定的文件
        file.transferTo(dest);
        // 压缩文件
        Thumbnails.of(finalPath)
                .size(480, 480)
                .outputFormat("jpg")
                .toFiles(Rename.SUFFIX_HYPHEN_THUMBNAIL);

        return true;
    } catch (IOException e) {
        log.error("IOException", e);
        return false;
    }`

I would like to ask whether webp format images are not supported for the time being, or I have a problem using them. Thank you!

Actual behavior

Please describe the actual behavior you are experiencing, including stack trace and other information which would help diagnose the issue.

Steps to reproduce the behavior

Please enter step-by-step instructions for reproducing the actual behavior. Including code can be helpful in diagnosing issue, but please keep the code to a minimal that will reproduce the behavior.

Environment

Please provide vendor and version information for the Operating System, JDK, and Thumbnailator. Please feel free to add any other information which may be pertinent.

zhaohui90-lee commented 1 year ago

the image format webp is not supported!

coobird commented 1 year ago

@zhaohui90-lee, Thumbnailator relies on Image I/O plugins available at runtime for reading and writing images. The default Java environment doesn't have support for WebP, so Thumbnailator cannot handle them.

If you want to handle other image formats, you'll need to add the appropriate Image I/O plugins to support them. For example, if you need WebP support, TwelveMonkeys ImageIO has read support for them. You'll basically just need to add a Maven dependency to the WebP plugin ("imageio-webp") and that should be all you'll need to do.

For more information, please refer to the FAQ on this topic.

zhangjianxing2011 commented 1 year ago

i use Thumbnails.of(url) it works well with webp image, my version of Thumbnails 0.4.20, but the question of mine is i want use the origin image size, am i don`t not about but i need set the size first,can i have any method to get the size?

coobird commented 1 year ago

@zhangjianxing2011 - Do you want to keep the same size as the original? Then you can use .scale(1.0):

Thumbnails.of("/path/to/image").scale(1.0).toFile("/path/to/thumbnail");

Next time when you have a question, feel free to open a new issue rather than ask in an already closed issue. Thanks!

zhangjianxing2011 commented 11 months ago

@zhangjianxing2011 - Do you want to keep the same size as the original? Then you can use .scale(1.0):

Thumbnails.of("/path/to/image").scale(1.0).toFile("/path/to/thumbnail");

Next time when you have a question, feel free to open a new issue rather than ask in an already closed issue. Thanks! Thank you very much,I will submit an closed issue with the answer