Пример #1
0
  /**
   * 跳转图片裁剪处理
   *
   * @author wqtan
   */
  @RequestMapping(value = "/cutImage")
  public String goCutImage(ModelMap model, HttpServletRequest request) {
    String status = "success";

    String imgPath = paramUtils.getParameter(request, "imgPath", "");
    model.addAttribute("imgPath", imgPath);

    File imgFile = new File(stringUtil.parseToPath(CommonConstants.ROOTPATH + "/" + imgPath));
    if (imgFile.isFile() && imgFile.exists()) {
      Image image = null;
      try {
        image = ImageTools.readImage(imgFile.getPath());
      } catch (UtilException e) {
        status = "error";
        return "/admin/cutImage";
      }

      int imgWidth = image.getWidth(null);
      int imgHeight = image.getHeight(null);
      model.addAttribute("imgWidth", imgWidth);
      model.addAttribute("imgHeight", imgHeight);
    } else {
      status = "error";
      return "/admin/qmt/magzine/cutImage";
    }
    model.addAttribute("status", status);

    int width = paramUtils.getIntParameter(request, "width", 0);
    model.addAttribute("width", width);

    int height = paramUtils.getIntParameter(request, "height", 0);
    model.addAttribute("height", height);

    // 回调只需要传函数名,参数为filepath
    String call = paramUtils.getParameter(request, "call", "");
    model.addAttribute("call", call);

    // 截取宽高
    String sw = paramUtils.getParameter(request, "sw", "");
    model.addAttribute("sw", sw);
    String sh = paramUtils.getParameter(request, "sh", "");
    model.addAttribute("sh", sh);
    // 图片存储类型
    String imgType = paramUtils.getParameter(request, "imgType", "");
    model.addAttribute("imgType", imgType);
    return "/admin/cutImage";
  }
Пример #2
0
 /**
  * 图片裁剪处理
  *
  * @author wqtan
  */
 @RequestMapping(value = "/doCutImage")
 @ResponseBody
 public String doCutImage(ModelMap model, CutInfo cutInfo, HttpServletRequest request)
     throws IOException {
   // 获得当前登陆用户
   String imgPath = paramUtils.getParameter(request, "imgPath", "");
   String imgType = paramUtils.getParameter(request, "imgType", "");
   if (null == imgType || imgType.trim().equals("")) {
     imgType = fileUtil.getSuffix(imgPath);
   } else {
     imgType = "." + imgType;
   }
   String message = "修改成功!";
   String status = "success";
   HashMap<String, Object> jsonMap = new HashMap<String, Object>();
   if (cutInfo.getCutHeight() <= 0
       || cutInfo.getCutWidth() <= 0
       || cutInfo.getCutX() < 0
       || cutInfo.getCutY() < 0) {
     status = "error";
     message = "请选择裁剪区域!";
   } else { // 获得要裁剪的图片
     // 更新头像
     // 获得原图的绝对路径
     imgPath = CommonConstants.ROOTPATH + imgPath;
     // 获得保存图的绝对路径
     String saveFile = imgPath + "_photo" + imgType;
     // 裁剪处理
     ImageTools.cutImage(cutInfo, imgPath, saveFile);
     // 获得头像的相对路径
     saveFile =
         stringUtil.parseToPath("/" + saveFile.substring(CommonConstants.ROOTPATH.length()));
     jsonMap.put("imgPath", saveFile);
   }
   jsonMap.put("status", status);
   jsonMap.put("message", stringUtil.encode(message));
   return jsonUtil.object2Json(jsonMap);
 }
Пример #3
0
 public Image dealImage(String imageFile) throws FileNotFoundException, IOException {
   Image image = ImageTools.readImage(imageFile);
   return this.dealImage(image);
 }