cropimg.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Insert title here</title>
  6. <style type="text/css">
  7. img {
  8. max-width: 100%; /* This rule is very important, please do not ignore this! */
  9. }
  10. </style>
  11. <script type="text/javascript" src="${ctx}/assets/lib/jquery/1.9.1/jquery.min.js"></script>
  12. <link href="${ctx}/assets/lib/cropper/cropper.css" rel="stylesheet">
  13. <script src="${ctx}/assets/lib/cropper/cropper.js"></script>
  14. <script type="text/javascript">
  15. var region;
  16. $(function() {
  17. $.init=function(){
  18. var ratio=eval($("#ratio").val());
  19. $('#cropimg').cropper({
  20. aspectRatio: ratio,
  21. viewMode:1,
  22. crop: function(e) {
  23. // Output the result data for cropping image.
  24. //console.log(e);
  25. region=e;
  26. }
  27. });
  28. }
  29. $.init();
  30. $("#ratio").change(function(){
  31. $('#cropimg').cropper("destroy");
  32. $.init();
  33. })
  34. $("#saveimg").click(function(){
  35. var imgSrc=$("#cropimg").attr("src");
  36. $.post("${ctx}/myconsole/cropimg/save",{imgSrc:imgSrc,x:Math.round(region.x),y:Math.round(region.y),x2:Math.round(region.width+region.x),y2:Math.round(region.height+region.y)},function(){
  37. parent.layer.closeAll();
  38. });
  39. })
  40. })
  41. </script>
  42. </head>
  43. <body>
  44. <div style="text-align: center">
  45. <div>
  46. <img id="cropimg" border="0" src="${imgSrc!}">
  47. </div>
  48. <div>
  49. 裁剪比例<input id="ratio" value="2.58/1" />
  50. <button id="saveimg">保存</button>
  51. </div>
  52. </div>
  53. </body>
  54. </html>