@RequestMapping("/process") public String imagePro(MultipartFile file) throws IOException { Map<String, Object> map = new HashMap<>();
String filename = null; String url = "http://127.0.0.1:8080/img/"; String localPath = null; String srcPath = null; String suffixName = null;
String type = file.getContentType(); if (type.equals("image/jpeg") || type.equals("image/jpg") || type.equals("image/png") || type.equals("image/gif")) { filename = file.getOriginalFilename(); suffixName = filename.substring(filename.lastIndexOf(".")); String uuidName = UUID.randomUUID().toString().replace("-", "") + suffixName; localPath = this.getClass().getResource("/").getPath() + "static/img/"; srcPath = localPath + uuidName;
if (FileUtils.upload(file, localPath, uuidName)) { map.put("srcPath", url + uuidName); map.put("srcMsg", "原图大小为:" + String.format("%.0f", file.getSize() / 1024f) + " KB"); } }
thumbnailImg(map, 200, 300, url, localPath, srcPath, suffixName); thumbnailImg2(map, 200, 300, url, localPath, srcPath, suffixName); proportionImg(map, 0.5, url, localPath, srcPath, suffixName); rotatingImg(map, 200, 300, 90, url, localPath, srcPath, suffixName); compressionImg(map, 1, 0.5, url, localPath, srcPath, suffixName); watermarkImg(map, 500, 500,"1.jpg",0.5f,0.8, url, localPath, srcPath, suffixName); tailoringImg(map, 300, 300, url, localPath, srcPath, suffixName); conversionImg(map, "gif", url, localPath, srcPath, suffixName); outputStream(map, "gif", url, localPath, srcPath, suffixName); bufferedImg(map, "bmp", url, localPath, srcPath, suffixName); return JSON.toJSONString(map); }
|