| | |
| | | import com.doumee.core.annotation.trace.Trace; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.FaceImageCompress; |
| | | import com.doumee.core.utils.FtpUtil; |
| | | import com.doumee.core.utils.aliyun.ALiYunUtil; |
| | | import io.swagger.annotations.Api; |
| | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | |
| | | @ApiOperation(value = "压缩图片", notes = "压缩图片", httpMethod = "POST", position = 6) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "folder", value = "文件夹", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class), |
| | | }) |
| | | @GetMapping(value = "/compressImg") |
| | | public void compressImg(@RequestParam(name = "folder") String folder, @RequestParam(name = "width") int width, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | FaceImageCompress. compressAllFiles(new File(folder),width); |
| | | } |
| | | |
| | | @ApiOperation(value = "上传", notes = "上传", httpMethod = "POST", position = 6) |
| | | @ApiImplicitParams({ |
| | |
| | | String date = DateUtil.getNowShortDate(); |
| | | String fName = date+"/"+ UUID.randomUUID()+".jpg"; |
| | | String fileName = folder+fName; |
| | | boolean r = ftp.uploadInputstream(compressImg(is),fileName); |
| | | // boolean r = ftp.uploadInputstream(compressImg(is),fileName); |
| | | boolean r = ftp.uploadInputstream(is,fileName); |
| | | if(r){ |
| | | context.put("success", true); |
| | | context.put("code", 200); |
| | |
| | | int compressedWidth = (int) (originalImage.getWidth() / compressionRatio); |
| | | int compressedHeight = (int) (originalImage.getHeight() / compressionRatio); |
| | | |
| | | BufferedImage compressedImage = new BufferedImage(compressedWidth, compressedHeight, originalImage.getType()); |
| | | BufferedImage compressedImage = new BufferedImage(compressedWidth, compressedHeight, BufferedImage.TYPE_INT_RGB); |
| | | Graphics2D graphics = compressedImage.createGraphics(); |
| | | graphics.drawImage(originalImage, 0, 0, compressedWidth, compressedHeight, null); |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | ImageOutputStream imOut = ImageIO.createImageOutputStream(byteArrayOutputStream); |
| | | ImageIO.write(compressedImage, "JPEG", imOut); |
| | | ImageIO.write(compressedImage, "jpg", imOut); |
| | | InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); |
| | | graphics.dispose(); |
| | | return inputStream; |
| | | }else{ |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | ImageOutputStream imOut = ImageIO.createImageOutputStream(byteArrayOutputStream); |
| | | ImageIO.write(originalImage, "JPEG", imOut); |
| | | ImageIO.write(originalImage, "jpg", imOut); |
| | | InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); |
| | | return inputStream; |
| | | } |