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;
}