使用 ImageMagick 将heic格式,转换成jpg格式
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
if ("heic".equals(suffix)){
String IMAGE_MAGICK_PATH = "D:\\Program Files\\ImageMagick-7.1.0-Q16-HDRI";
// 日期+uuid作为文件名
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String fileName = formatter.format(date) + Uuid19Util.uuid();
String rootFilePath = "C:\\Users\\Administrator\\Desktop\\test_heic\\" + fileName + originalFilename;
String rootFilePath1 = "C:\\Users\\Administrator\\Desktop\\test_heic\\" + fileName + "1.jpg" ;
FileUtil.writeBytes(file.getBytes(), rootFilePath);
ConvertCmd cmd = new ConvertCmd();
cmd.setSearchPath(IMAGE_MAGICK_PATH);
IMOperation op = new IMOperation();
op.addImage(rootFilePath); //需要转换的图片路径
op.addImage(rootFilePath1); //转换出来的图片路径
//启动
cmd.run(op);
byte[] bytes = FileUtil.readBytes(rootFilePath1); // 通过文件的路径读取文件字节流
InputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
imgUrl = ossClientService.uploadImage2Oss(byteArrayInputStream, fileUploadPathProperty.getConsultPic());
if (!imgUrl.isEmpty()){
File file1 = new File(rootFilePath);
File file2 = new File(rootFilePath1);
file1.delete();
file2.delete();
}
}else {
imgUrl = ossClientService.uploadImage2Oss(file.getInputStream(), fileUploadPathProperty.getConsultPic());
}