当前位置:   article > 正文

【jquery】使用canvas实现前端裁剪图片,并上传到服务器_jquery canvas上传图片 nodejs

jquery canvas上传图片 nodejs

这里需要用到jquery Jcrop 插件实现前端选择图片区域效果

然后使用canvas裁剪图片,并把base64位的toDataURL图片转换成blob

最后使用XMLHttpRequest上传到服务器。


预览效果:


整体代码:

  1. <!doctype html>
  2. <html>
  3. <head>
  4.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  7.   <meta name="description" id="description1" content="1">
  8.   <meta name="renderer" content="webkit">
  9.   <meta name="format-detection" content="telephone=no">
  10.   <title>图片上传</title>
  11.     <style type="text/css">
  12.     * {
  13.         box-sizing: border-box; /* h5 */
  14.         -moz-box-sizing: border-box; /* Firefox */
  15.         -webkit-box-sizing: border-box; /* Safari */
  16.         margin: 0;
  17.         padding: 0;
  18.         outline: 0 none;
  19.         font-weight: inherit;
  20.         font-style: inherit;
  21.         font-family: inherit;
  22.         vertical-align: baseline;
  23.     }
  24.     .jcrop-holder {
  25.         direction: ltr;
  26.         text-align: center;
  27.         margin: 0 auto;
  28.         /* IE10 touch compatibility */
  29.         -ms-touch-action: none;
  30.     }
  31.         /* Selection Border */
  32.     .jcrop-vline,
  33.     .jcrop-hline {
  34.         background: #ffffff url("Jcrop.gif");
  35.         font-size: 0;
  36.         position: absolute;
  37.     }
  38.     .jcrop-vline {
  39.         height: 100%;
  40.         width: 1px !important;
  41.     }
  42.     .jcrop-vline.right {
  43.         right: 0;
  44.     }
  45.     .jcrop-hline {
  46.         height: 1px !important;
  47.         width: 100%;
  48.     }
  49.     .jcrop-hline.bottom {
  50.         bottom: 0;
  51.     }
  52.         /* Invisible click targets */
  53.     .jcrop-tracker {
  54.         height: 100%;
  55.         width: 100%;
  56.         /* "turn off" link highlight */
  57.         -webkit-tap-highlight-color: tra
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/228005
推荐阅读
相关标签
  

闽ICP备14008679号