【代码】JCrop头像剪辑预览+后端实现

头像上传的插件似乎要用到的时候非常少,查了下网上提供的插件,有些还是使用GPL协议的,果断弃之。

最终选用了JCrop来实现(补充下JCrop提供多种编辑方式和样式,使用MIT License)。

MIT License:

The MIT License

Copyright ©2008 Kelly Hallman and Deep Liquid Group

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


头像上传的部分功能,只要是流程是这样:

1. 用户选择图片,上传至服务器后返回图片地址或其他参数返回给用户界面显示(上传的图片大小要做限制,如果图片大小符合要求但px即像素太大,也需要对图片进行一点比例的缩放处理,再返回)

2. 用户修改或者剪辑图片,根据需要剪辑图片大小和位置(可提供预览界面)

3. 保存图片(保存即将图片选取的坐标值传递至服务器,对图片做剪辑,并缩放至你显示给用户头像的大小)

前端效果一(选择图片):


【代码】JCrop头像剪辑预览+后端实现_第1张图片

效果一代码:

   1: 
"<%=request.getContextPath() %>/uploadImg.do"
   2:                                         name="imgForm1" enctype="multipart/form-data" method="POST">
   3:                                         "file" name="imgFile" οnchange="submit();" />
   4:                                     

前端效果二(服务器返回后生成图片提供编辑):


【代码】JCrop头像剪辑预览+后端实现_第2张图片


前端效果二代码:

   1: <script src="./scripts/jquery.min.js">script>
   1:  
   2: 
   2: "stylesheet" href="./css/jquery.Jcrop.css" type="text/css" />
   3: <%
   4: Object imgWO = request.getAttribute("imgWidth");
   5: int imgWidth = 0;
   6: if(null != imgWO) {
   7:     imgWidth = (Integer)imgWO;
   8: }
   9: Object imgHO = request.getAttribute("imgHeight");
  10: int imgHeight= 0;
  11: if(null != imgHO) {
  12:     imgHeight = (Integer)imgHO;
  13: }
  14: %>
  15: 
                    
                    

你可能感兴趣的:(string,null,file,jquery,exception,action,Java,Code,j2ee,google,study)