javascript - cropper.jscant 通过 blueimp 初始化 blob 图像 <img> 标签

标签 javascript jquery blueimp cropper

所以我想要的是:

选择输入类型文件的图像, 缩小blueimp , 使用 cropper.js 裁剪该图像

因此 blueimp 部分工作正常,图像大小调整为 maxWidth 属性并附加为 <img>标记为“#imagearea”,然后我想根据该标记初始化cropper.js,就像在文档中一样,这是我的代码

  document.getElementById('file-input').onchange = function (e) {
      var loadingImage = loadImage(
          e.target.files[0],
          function (img) {


            $(img).attr("style","max-width: 100%;")
            $('#imagearea').append(img)
            // now i see the image and when i inspect dom its a <img> tag

            // so lets initialize the cropper
            $('#imagearea').find("img").cropper({
              aspectRatio: 16 / 9,
              crop: function(e) {

              }
            });
          },
          {maxWidth: 1280}
      );

  };

但是在初始化裁剪器时, 首先我收到 404 错误,例如

GET blob:http://foo.bar/64c77709-29f7-44ba-8772-49517e7976e5 404 (Not Found)

然后

未捕获的范围错误:偏移量超出了 DataView 的范围 在DataView.getUint8() 在米(6eaf333.js:7051) 在 e.value (6eaf333.js:7051) 在 XMLHttpRequest.n.onload (6eaf333.js:7051)

最佳答案

请使用“noRevoke”选项。

document.getElementById('file-input').onchange = function (e) {
      var loadingImage = loadImage(
          e.target.files[0],
          function (img) {


            $(img).attr("style","max-width: 100%;")
            $('#imagearea').append(img)
            // now i see the image and when i inspect dom its a <img> tag

            // so lets initialize the cropper
            $('#imagearea').find("img").cropper({
              aspectRatio: 16 / 9,
              crop: function(e) {

              }
            });
          },
          {maxWidth: 1280,noRevoke: true}
      );

  };

关于javascript - cropper.jscant 通过 blueimp 初始化 blob 图像 <img> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43669679/

相关文章:

javascript - 如何在基于 'family-tree' 的 d3.js 中显示婚姻?

javascript - Apache Web 服务器消息

javascript - 不同大小的 block 最好分配给固定大小的桶

jquery - 如何直接在图像下获取菜单栏?

ajax - Blueimp jQuery 文件上传和 symfony2 : issue with custom upload handler

php - 如何使用 jQuery BlueImp 上传多个文件 + symfony3 获取与每个文件对应的错误

javascript - 如何在 JavaScript 中基于另一个对象动态创建属性和对象?

javascript - 我可以使用 JS 一次使用 JSON 数组中的一个字符串吗?

javascript - html 表中可编辑字段的更改事件仅影响顶行计算字段

javascript - jQuery File Uploader IE9 不在上传时发布任何参数