Last active
December 16, 2015 07:58
-
-
Save wdfx100/5402531 to your computer and use it in GitHub Desktop.
#上传头像功能#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //jar:ImageUtil.jar filters-2.0.235.jar | |
| //jquert.jcrop.js jcrop.css | |
| <img alt="" src="http://www.wdfx100.com/upload/${fileName }"> | |
| <form action="jcrop" method="post"> | |
| <input type="hidden" name="fileName" value="${fileName}"> | |
| <input type="hidden" name="x1" id="x"> | |
| <input type="hidden" name="y1" id="y"> | |
| <input type="hidden" name="x2" id="x2"> | |
| <input type="hidden" name="y2" id="y2"> | |
| <input type="submit" value="剪裁"/> | |
| </form> | |
| $(function(){ | |
| $("img").Jcrop({ | |
| onChange: showCoords, | |
| onSelect: showCoords | |
| }); | |
| function showCoords(c) | |
| { | |
| $('#x').val(c.x); | |
| $('#y').val(c.y); | |
| $('#x2').val(c.x2); | |
| $('#y2').val(c.y2); | |
| } | |
| }); | |
| String fileName = request.getParameter("fileName"); | |
| int x1 = Integer.parseInt(request.getParameter("x1")); | |
| int y1 = Integer.parseInt(request.getParameter("y1")); | |
| int x2 = Integer.parseInt(request.getParameter("x2")); | |
| int y2 = Integer.parseInt(request.getParameter("y2")); | |
| File file = new File(getServletContext().getRealPath("/")+"upload",fileName); | |
| Image img = ImageLoader.fromFile(file); | |
| img.crop(x1, y1, x2, y2).writeToFile(file); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment