SpringBoot 上传压缩图片抛异常 Unsupported Image Type

抛出异常的位置

Thumbnails.of(contextPath).size(1920,1080).outputQuality(1f).outputFormat(“jpg”).toFile(contextPat)

原因:

ps或其他软件处理过的图片保存为jpg格式时,默认的模式是CMYK模式(这是给印刷机用的)。

解决办法, 添加imageio-tiffimageio-jpeg引用, gradle构建项目添加如下:

    // https://mvnrepository.com/artifact/com.twelvemonkeys.imageio/imageio-jpeg
    compile group: 'com.twelvemonkeys.imageio', name: 'imageio-jpeg', version: '3.2.1'

    // https://mvnrepository.com/artifact/com.twelvemonkeys.imageio/imageio-tiff
    compile group: 'com.twelvemonkeys.imageio', name: 'imageio-tiff', version: '3.4.1'

猜你喜欢

转载自blog.csdn.net/weixin_39973810/article/details/89633555