剪裁圆形图片cropie
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | <!DOCTYPE html> <html> <head> <script src= "https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js" ></script> <script src= "https://cdn.bootcss.com/croppie/2.6.2/croppie.js" ></script> <link rel= "Stylesheet" href= "https://cdn.bootcss.com/croppie/2.6.2/croppie.css" /> <style> button, a.btn { background-color: #189094; color: white; padding: 10px 15px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, 0.5); font-size: 16px; cursor: pointer; text-decoration: none; text-shadow: none; } button:focus { outline: 0; } .file-btn { position: relative; } .file-btn input[type= "file" ] { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; } .actions { padding: 5px 0; } .actions button { margin-right: 5px; } .pop_main{display:none} .pop_con{ width: 400px; height: 400px; background: #fff; z-index: 100; position: relative;} .pop_mask{background-color: rgba(0, 0, 0, 0.5);position: absolute; width: 100%; left: 0; top: 0; bottom: 0;} </style> </head> <body> <div class = "actions" > <button class = "file-btn" > <span>上传</span> <input type= "file" id= "upload" value= "选择图片文件" /> </button> <div class = "pop_main" > <div class = "pop_con" > <div> <button class = "pop_close" >x</button> </div> <div class = "crop" > <div id= "upload-demo" ></div> <button class = "upload-result" >裁剪</button> </div> </div> <div class = "pop_mask" ></div> </div> <div id= "result" ></div> </div> <script> $(function(){ var $uploadCrop; function readFile(input) { if (input.files && input.files[0]) { console.log( "file----" ,input.files[0]) var reader = new FileReader(); reader.onload = function (e) { $uploadCrop.croppie( 'bind' , { url: e.target.result }); } reader.readAsDataURL(input.files[0]); } else { alert( "Sorry - you're browser doesn't support the FileReader API" ); } } $uploadCrop = $( '#upload-demo' ).croppie({ viewport: { width: 200, height: 200, type: 'circle' }, boundary: { width: 300, height: 300 } }); $( '#upload' ). on ( 'change' , function () { $( ".pop_main" ).show(); $( ".pop_con" ).css({ 'top' :0, 'opacity' :0}) $( ".pop_con" ).animate({ 'top' : '50%' , 'opacity' :1}) readFile( this ); }); $( '.upload-result' ). on ( 'click' , function (ev) { $uploadCrop.croppie( 'result' , 'canvas' ).then(function (resp) { console.log( "file---2" ,resp) popupResult({ src: resp }); }); }); $( '.pop_close' ). on ( 'click' ,function(ev){ $( ".pop_main" ).hide() var file = $( "#upload" ) file.after(file.clone().val( "" )); file.remove(); }) function popupResult(result) { var html; if (result.html) { html = result.html; } if (result.src) { html = '<img src="' + result.src + '" />' ; } $( "#result" ).html(html); } }); </script> </body> </html> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类