heic 转png (linux)

1、上传环境文件到指定目录(/data/img_insert/components/),记得给环境文件777权限

所需文件下载地址:
链接:https://pan.baidu.com/s/1w-cwZzHIIG2oWN3DHGvIkQ 
提取码:99el
链接:https://pan.baidu.com/s/1t0aZg1nOPd0sxCUj0qg_9Q 
提取码:yqvj

2、实现代码如下:

public synchronized static InputStream convertHeicToJpg(String imgUrl) throws Exception {

        String downloadPath = "/data/img_insert/downloadImg/" + System.currentTimeMillis() + ".heic";
        String saveHeicPath = "/data/img_insert/downloadImg/" + System.currentTimeMillis() + ".png";
        //先下载文件
        downloadFile(imgUrl, downloadPath);
        IMOperation operation = new IMOperation();
        ConvertCmd convert = new ConvertCmd();
  //路径下配置的事imagemagick的环境文件 同目录的convert 和magick 文件
        ProcessStarter.setGlobalSearchPath("/data/img_insert/components/");
        operation.addImage(downloadPath, saveHeicPath);

        try {
            convert.run(operation);
            File file = new File(saveHeicPath);
            if (file.exists()) {
                return new FileInputStream(file);
            }
        } catch (Exception e) {
            log.error("转换jpeg失败,url:{},原因:{}", imgUrl, e.getMessage());
        }
        new File(downloadPath).delete();
        new File(saveHeicPath).delete();
        return null;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值