| | |
| | | * 处理图片文件 |
| | | */ |
| | | public Map<String, Object> processImage(File file, int width, int height, |
| | | float quality, String format,boolean deleteY) throws IOException { |
| | | float quality, String format) throws IOException { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | | // 读取图片 |
| | |
| | | result.put("compressedHeight", height > 0 ? height : originalHeight); |
| | | result.put("base64", dataUrl); |
| | | result.put("message", "图片压缩成功"); |
| | | if (deleteY) { |
| | | file.delete(); |
| | | result.put("originalDeleted", false); |
| | | result.put("message", "图片压缩成功"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | |
| | | * 处理视频文件:生成Base64编码的封面 (使用JavaCV) |
| | | */ |
| | | public Map<String, Object> processVideo(File file, int width, int height, |
| | | float quality, String format, boolean deleteY) { |
| | | float quality, String format) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | | try { |
| | |
| | | log.error("视频封面生成失败", e); |
| | | result.put("success", false); |
| | | result.put("message", "封面生成失败: " + e.getMessage()); |
| | | } finally { |
| | | // 清理临时文件 |
| | | if (deleteY && file != null && file.exists()) { |
| | | try { |
| | | file.delete(); |
| | | } catch (Exception e) { |
| | | log.warn("删除临时视频文件时出错", e); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |