zoukankan      html  css  js  c++  java
  • java 上传图片压缩

     public static void uploadFile(MultipartFile multfile, String filePath) throws Exception {
    File targetFile = new File(filePath);
    if (!targetFile.exists()) {
    targetFile.mkdirs();
    }
    try {
    //按比例压缩
    Thumbnails.of(multfile.getInputStream()).scale(0.4f).outputQuality(0.25f).toFile(filePath);//filePath:上传图片的路径eg: xxx/xxx/xxx.jpg
    //按尺寸压缩
    //Thumbnails.of(multfile.getInputStream()).size(100,100).keepAspectRatio(false).toFile(filePath);
    } catch (Exception e) {
    log.info("压缩图片出现异常:", e);
    }
    }

    <dependency>
    <groupId>net.coobird</groupId>
    <artifactId>thumbnailator</artifactId>
    <version>0.4.8</version>
    </dependency>
  • 相关阅读:
    导航
    占位
    django(一)
    进程与线程
    网络编程
    反射 单例模式
    面向对象及命名空间
    logging,包
    模块(二)os hashlib
    装饰器&递归
  • 原文地址:https://www.cnblogs.com/austinspark-jessylu/p/9408479.html
Copyright © 2011-2022 走看看