ImgCropper.asp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <base target="_self" />
  6. <title>图片切割系统</title>
  7. <script type="text/javascript">
  8. var isIE = (document.all) ? true : false;
  9. var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
  10. var $ = function (id) {
  11. return "string" == typeof id ? document.getElementById(id) : id;
  12. };
  13. var Class = {
  14. create: function() {
  15. return function() { this.initialize.apply(this, arguments); }
  16. }
  17. }
  18. var Extend = function(destination, source) {
  19. for (var property in source) {
  20. destination[property] = source[property];
  21. }
  22. }
  23. var Bind = function(object, fun) {
  24. return function() {
  25. return fun.apply(object, arguments);
  26. }
  27. }
  28. var BindAsEventListener = function(object, fun) {
  29. var args = Array.prototype.slice.call(arguments).slice(2);
  30. return function(event) {
  31. return fun.apply(object, [event || window.event].concat(args));
  32. }
  33. }
  34. var CurrentStyle = function(element){
  35. return element.currentStyle || document.defaultView.getComputedStyle(element, null);
  36. }
  37. function addEventHandler(oTarget, sEventType, fnHandler) {
  38. if (oTarget.addEventListener) {
  39. oTarget.addEventListener(sEventType, fnHandler, false);
  40. } else if (oTarget.attachEvent) {
  41. oTarget.attachEvent("on" + sEventType, fnHandler);
  42. } else {
  43. oTarget["on" + sEventType] = fnHandler;
  44. }
  45. };
  46. function removeEventHandler(oTarget, sEventType, fnHandler) {
  47. if (oTarget.removeEventListener) {
  48. oTarget.removeEventListener(sEventType, fnHandler, false);
  49. } else if (oTarget.detachEvent) {
  50. oTarget.detachEvent("on" + sEventType, fnHandler);
  51. } else {
  52. oTarget["on" + sEventType] = null;
  53. }
  54. };
  55. </script>
  56. <script type="text/javascript" src="ImgCropper.js"></script>
  57. <script type="text/javascript" src="Drag.js"></script>
  58. <script type="text/javascript" src="Resize.js"></script>
  59. <style type="text/css">
  60. #rRightDown,#rLeftDown,#rLeftUp,#rRightUp,#rRight,#rLeft,#rUp,#rDown{
  61. position:absolute;
  62. background:#FFF;
  63. border: 1px solid #333;
  64. width: 6px;
  65. height: 6px;
  66. z-index:500;
  67. font-size:0;
  68. opacity: 0.5;
  69. filter:alpha(opacity=50);
  70. }
  71. #rLeftDown,#rRightUp{cursor:ne-resize;}
  72. #rRightDown,#rLeftUp{cursor:nw-resize;}
  73. #rRight,#rLeft{cursor:e-resize;}
  74. #rUp,#rDown{cursor:n-resize;}
  75. #rLeftDown{left:0px;bottom:0px;}
  76. #rRightUp{right:0px;top:0px;}
  77. #rRightDown{right:0px;bottom:0px;background-color:#00F;}
  78. #rLeftUp{left:0px;top:0px;}
  79. #rRight{right:0px;top:50%;margin-top:-4px;}
  80. #rLeft{left:0px;top:50%;margin-top:-4px;}
  81. #rUp{top:0px;left:50%;margin-left:-4px;}
  82. #rDown{bottom:0px;left:50%;margin-left:-4px;}
  83. #bgDiv{width:368px; height:265px; border:1px solid #666666; position:relative;}
  84. #dragDiv{border:1px dashed #fff; width:100px; height:60px; top:50px; left:50px; cursor:move; }
  85. body{margin:10px}
  86. </style>
  87. </head>
  88. <body>
  89. <table width="750" border="0" cellspacing="0" cellpadding="0">
  90. <tr>
  91. <td width="368"><div id="bgDiv">
  92. <div id="dragDiv">
  93. <div id="rRightDown"> </div>
  94. <div id="rLeftDown"> </div>
  95. <div id="rRightUp"> </div>
  96. <div id="rLeftUp"> </div>
  97. <div id="rRight"> </div>
  98. <div id="rLeft"> </div>
  99. <div id="rUp"> </div>
  100. <div id="rDown"></div>
  101. </div>
  102. </div></td>
  103. <td align="center"><div id="viewDiv" style="width:368px; height:265px;"> </div></td>
  104. </tr>
  105. </table>
  106. <br />
  107. <input name="" type="button" value="生成图片" onclick="Create()" />
  108. <br /><br />
  109. <img id="imgCreat" style="display:none;" />
  110. <script>
  111. var ic = new ImgCropper("bgDiv", "dragDiv", "<%=Request.QueryString("imgurl")%>", {
  112. Width: 368, Height: 265, Color: "#000",
  113. Resize: true,Scale:true,Ratio:368/265,
  114. Right: "rRight", Left: "rLeft", Up: "rUp", Down: "rDown",
  115. RightDown: "rRightDown", LeftDown: "rLeftDown", RightUp: "rRightUp", LeftUp: "rLeftUp",
  116. Preview: "viewDiv", viewWidth: 368, viewHeight: 265
  117. })
  118. function Create(){
  119. var p = ic.Url, o = ic.GetPos();
  120. x = o.Left,
  121. y = o.Top,
  122. w = o.Width,
  123. h = o.Height,
  124. pw = ic._layBase.width,
  125. ph = ic._layBase.height;
  126. //$("imgCreat").onload = function(){ this.style.display = ""; }
  127. //$("imgCreat").src = "ImgCropper1.asp?p=" + p + "&x=" + x + "&y=" + y + "&w=" + w + "&h=" + h + "&pw=" + pw + "&ph=" + ph + "&" + Math.random();
  128. //alert(p + "&x=" + x + "&y=" + y + "&w=" + w + "&h=" + h + "&pw=" + pw + "&ph=" + ph)
  129. document.location.replace("ImgCropper1.asp?p=" + p + "&x=" + x + "&y=" + y + "&w=" + w + "&h=" + h + "&pw=" + pw + "&ph=" + ph + "&" + Math.random());
  130. }
  131. </script>
  132. </body>
  133. </html>