如何使用存储在亚马逊网络服务上的 jquery 裁剪器编辑图像?

吉里什

我正在使用用于编辑图像jquery 裁剪器 (v 0.7.9) 插件我刚刚按照插件页面中给出的说明在我的机器上创建了一个简单的示例。如果图像存储在我的机器上,它工作正常。但如果图像来自亚马逊存储桶,则它不起作用。请给我以下代码的建议。

<div class="eg-wrapper" id="divContainer" style="height: 400px;width: 400px;">
        <img class="cropper" id="editImage" crossorigin="anonymous" src="http://review-rating-bucket.s3.amazonaws.com/9991710/149270397024phpG2BOu7.jpeg" alt="Picture" height="400" width="400">
    </div>
    <button class="btn btn-primary" id="getDataURL" type="button">Get Data URL</button>
<button class="btn btn-primary" id="getDataURL2" type="button">Get Data URL (JPG)</button>
<button class="btn btn-primary" id="getDataURL3" type="button">Get Data URL (160*90)</button>
<button class="btn btn-primary" id="rotate" type="button">Rotate</button>
<button class="btn btn-primary" id="zoom" type="button">Zoom</button>
<button class="btn btn-info" id="getImageData" type="button">Get Image Data</button>
<button class="btn btn-info" id="getData2" type="button">Get Data (Rounded)</button>
<button class="btn btn-info" id="getData" type="button">Get Data</button>
<button class="btn btn-warning" id="reset" type="button">Reset</button>
<button class="btn  btn-warning" id="reset2" type="button">Reset (deep)</button>
<button class="btn btn-primary" id="clear" type="button">Clear</button>
<button class="btn btn-danger" id="destroy" type="button">Destroy</button>
<button class="btn btn-success" id="enable" type="button">Enable</button>
<button class="btn btn-warning" id="disable" type="button">Disable</button>
<button class="btn btn-info" id="zoomIn" type="button">Zoom In</button>
<button class="btn btn-info" id="zoomOut" type="button">Zoom Out</button>
<button class="btn btn-info" id="rotateLeft" type="button">Rotate Left</button>
<button class="btn btn-info" id="rotateRight" type="button">Rotate Right</button>
<button class="btn btn-primary" id="setData" type="button">Set Data</button>
<br/>
<textarea class="form-control" id="dataURL" rows="10"></textarea>
<script>
    var $image = $("#editImage"),
          $dataX = $("#dataX"),
          $dataY = $("#dataY"),
          $dataHeight = $("#dataHeight"),
          $dataWidth = $("#dataWidth"),
          console = window.console || { log: function () {} },
          cropper;

      $image.cropper({
        // autoCropArea: 1,
        data: {
          x: 50,
          y: 50,
          width: 200,
          height: 200
        },

        // multiple: true,
        // autoCrop: false,
        // dragCrop: false,
        // dashed: false,
        // modal: false,
        // movable: false,
        // resizable: false,
        // zoomable: false,
        // rotatable: false,
        // checkImageOrigin: false,

        // maxWidth: 480,
        // maxHeight: 270,
        // minWidth: 160,
        // minHeight: 90,

        done: function (data) {
          $dataX.val(data.x);
          $dataY.val(data.y);
          $dataHeight.val(data.height);
          $dataWidth.val(data.width);
        },

        build: function (e) {
          console.log(e.type);
        },

        built: function (e) {
          console.log(e.type);
        },

        dragstart: function (e) {
          console.log(e.type);
        },

        dragmove: function (e) {
          console.log(e.type);
        },

        dragend: function (e) {
          console.log(e.type);
        }
      });

      cropper = $image.data("cropper");

      $image.on({
        "build.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "built.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "dragstart.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "dragmove.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "dragend.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        }
      });

      $("#reset").click(function () {
        $image.cropper("reset");
      });

      $("#reset2").click(function () {
        $image.cropper("reset", true);
      });

      $("#clear").click(function () {
        $image.cropper("clear");
      });

      $("#destroy").click(function () {
        $image.cropper("destroy");
      });

      $("#enable").click(function () {
        $image.cropper("enable");
      });

      $("#disable").click(function () {
        $image.cropper("disable");
      });

      $("#zoom").click(function () {
        $image.cropper("zoom", $("#zoomWith").val());
      });

      $("#zoomIn").click(function () {
        $image.cropper("zoom", 0.1);
      });

      $("#zoomOut").click(function () {
        $image.cropper("zoom", -0.1);
      });

      $("#rotate").click(function () {
        $image.cropper("rotate", $("#rotateWith").val());
      });

      $("#rotateLeft").click(function () {
        $image.cropper("rotate", -90);
      });

      $("#rotateRight").click(function () {
        $image.cropper("rotate", 90);
      });

      var $inputImage = $("#inputImage"),
          blobURL;

      if (window.URL) {
        $inputImage.change(function () {
          var files = this.files,
              file;

          if (files && files.length) {
            file = files[0];

            if (/^image\/\w+$/.test(file.type)) {
              if (blobURL) {
                URL.revokeObjectURL(blobURL); // Revoke the old one
              }

              blobURL = URL.createObjectURL(file);
              $image.cropper("reset", true).cropper("replace", blobURL);
              $inputImage.val("");
            }
          }
        });
      } else {
        $inputImage.parent().remove();
      }

      $("#setAspectRatio").click(function () {
        $image.cropper("setAspectRatio", $("#aspectRatio").val());
      });

      $("#replace").click(function () {
        $image.cropper("replace", $("#replaceWith").val());
      });

      $("#getImageData").click(function () {
        $("#showImageData").val(JSON.stringify($image.cropper("getImageData")));
      });

      $("#setData").click(function () {
        $image.cropper("setData", {
          x: $dataX.val(),
          y: $dataY.val(),
          width: $dataWidth.val(),
          height: $dataHeight.val()
        });
      });

      $("#getData").click(function () {
        $("#showData").val(JSON.stringify($image.cropper("getData")));
      });

      $("#getData2").click(function () {
        $("#showData").val(JSON.stringify($image.cropper("getData", true)));
      });

      $("#getDataURL").click(function () {
        var dataURL = $image.cropper("getDataURL");
        alert(dataURL);
        $("#dataURL").text(dataURL);
        $("#showDataURL").html('<img src="' + dataURL + '">');
      });

      $("#getDataURL2").click(function () {
        var dataURL = $image.cropper("getDataURL", "image/jpeg");
        alert(dataURL);
        $("#dataURL").text(dataURL);
        $("#showDataURL").html('<img src="' + dataURL + '">');
      });

      $("#getDataURL3").click(function () {
        var dataURL = $image.cropper("getDataURL", {
          width: 160,
          height: 90
        });
        alert(dataURL);
        $("#dataURL").text(dataURL);
        $("#showDataURL").html('<img src="' + dataURL + '">');
      });
</script>
阿尔瓦罗·图宗

我做了这个演示,开始研究和解决你在亚马逊上的问题。而且亚马逊的图片没有显示出来。当尝试直接访问图像时,它被下载了。

所以我认为这个图像会是亚马逊的权限问题。

<div class="eg-wrapper" id="divContainer" style="height: 400px;width: 400px;">
        <img class="cropper" id="editImage" crossorigin="anonymous" src="http://review-rating-bucket.s3.amazonaws.com/9991710/149270397024phpG2BOu7.jpeg" alt="Picture" height="400" width="400">
    </div>
    <button class="btn btn-primary" id="getDataURL" type="button">Get Data URL</button>
<button class="btn btn-primary" id="getDataURL2" type="button">Get Data URL (JPG)</button>
<button class="btn btn-primary" id="getDataURL3" type="button">Get Data URL (160*90)</button>
<button class="btn btn-primary" id="rotate" type="button">Rotate</button>
<button class="btn btn-primary" id="zoom" type="button">Zoom</button>
<button class="btn btn-info" id="getImageData" type="button">Get Image Data</button>
<button class="btn btn-info" id="getData2" type="button">Get Data (Rounded)</button>
<button class="btn btn-info" id="getData" type="button">Get Data</button>
<button class="btn btn-warning" id="reset" type="button">Reset</button>
<button class="btn  btn-warning" id="reset2" type="button">Reset (deep)</button>
<button class="btn btn-primary" id="clear" type="button">Clear</button>
<button class="btn btn-danger" id="destroy" type="button">Destroy</button>
<button class="btn btn-success" id="enable" type="button">Enable</button>
<button class="btn btn-warning" id="disable" type="button">Disable</button>
<button class="btn btn-info" id="zoomIn" type="button">Zoom In</button>
<button class="btn btn-info" id="zoomOut" type="button">Zoom Out</button>
<button class="btn btn-info" id="rotateLeft" type="button">Rotate Left</button>
<button class="btn btn-info" id="rotateRight" type="button">Rotate Right</button>
<button class="btn btn-primary" id="setData" type="button">Set Data</button>
<br/>
<textarea class="form-control" id="dataURL" rows="10"></textarea>
<script>
    var $image = $("#editImage"),
          $dataX = $("#dataX"),
          $dataY = $("#dataY"),
          $dataHeight = $("#dataHeight"),
          $dataWidth = $("#dataWidth"),
          console = window.console || { log: function () {} },
          cropper;

      $image.cropper({
        // autoCropArea: 1,
        data: {
          x: 50,
          y: 50,
          width: 200,
          height: 200
        },

        // multiple: true,
        // autoCrop: false,
        // dragCrop: false,
        // dashed: false,
        // modal: false,
        // movable: false,
        // resizable: false,
        // zoomable: false,
        // rotatable: false,
        // checkImageOrigin: false,

        // maxWidth: 480,
        // maxHeight: 270,
        // minWidth: 160,
        // minHeight: 90,

        done: function (data) {
          $dataX.val(data.x);
          $dataY.val(data.y);
          $dataHeight.val(data.height);
          $dataWidth.val(data.width);
        },

        build: function (e) {
          console.log(e.type);
        },

        built: function (e) {
          console.log(e.type);
        },

        dragstart: function (e) {
          console.log(e.type);
        },

        dragmove: function (e) {
          console.log(e.type);
        },

        dragend: function (e) {
          console.log(e.type);
        }
      });

      cropper = $image.data("cropper");

      $image.on({
        "build.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "built.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "dragstart.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "dragmove.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        },
        "dragend.cropper": function (e) {
          console.log(e.type);
          // e.preventDefault();
        }
      });

      $("#reset").click(function () {
        $image.cropper("reset");
      });

      $("#reset2").click(function () {
        $image.cropper("reset", true);
      });

      $("#clear").click(function () {
        $image.cropper("clear");
      });

      $("#destroy").click(function () {
        $image.cropper("destroy");
      });

      $("#enable").click(function () {
        $image.cropper("enable");
      });

      $("#disable").click(function () {
        $image.cropper("disable");
      });

      $("#zoom").click(function () {
        $image.cropper("zoom", $("#zoomWith").val());
      });

      $("#zoomIn").click(function () {
        $image.cropper("zoom", 0.1);
      });

      $("#zoomOut").click(function () {
        $image.cropper("zoom", -0.1);
      });

      $("#rotate").click(function () {
        $image.cropper("rotate", $("#rotateWith").val());
      });

      $("#rotateLeft").click(function () {
        $image.cropper("rotate", -90);
      });

      $("#rotateRight").click(function () {
        $image.cropper("rotate", 90);
      });

      var $inputImage = $("#inputImage"),
          blobURL;

      if (window.URL) {
        $inputImage.change(function () {
          var files = this.files,
              file;

          if (files && files.length) {
            file = files[0];

            if (/^image\/\w+$/.test(file.type)) {
              if (blobURL) {
                URL.revokeObjectURL(blobURL); // Revoke the old one
              }

              blobURL = URL.createObjectURL(file);
              $image.cropper("reset", true).cropper("replace", blobURL);
              $inputImage.val("");
            }
          }
        });
      } else {
        $inputImage.parent().remove();
      }

      $("#setAspectRatio").click(function () {
        $image.cropper("setAspectRatio", $("#aspectRatio").val());
      });

      $("#replace").click(function () {
        $image.cropper("replace", $("#replaceWith").val());
      });

      $("#getImageData").click(function () {
        $("#showImageData").val(JSON.stringify($image.cropper("getImageData")));
      });

      $("#setData").click(function () {
        $image.cropper("setData", {
          x: $dataX.val(),
          y: $dataY.val(),
          width: $dataWidth.val(),
          height: $dataHeight.val()
        });
      });

      $("#getData").click(function () {
        $("#showData").val(JSON.stringify($image.cropper("getData")));
      });

      $("#getData2").click(function () {
        $("#showData").val(JSON.stringify($image.cropper("getData", true)));
      });

      $("#getDataURL").click(function () {
        var dataURL = $image.cropper("getDataURL");
        alert(dataURL);
        $("#dataURL").text(dataURL);
        $("#showDataURL").html('<img src="' + dataURL + '">');
      });

      $("#getDataURL2").click(function () {
        var dataURL = $image.cropper("getDataURL", "image/jpeg");
        alert(dataURL);
        $("#dataURL").text(dataURL);
        $("#showDataURL").html('<img src="' + dataURL + '">');
      });

      $("#getDataURL3").click(function () {
        var dataURL = $image.cropper("getDataURL", {
          width: 160,
          height: 90
        });
        alert(dataURL);
        $("#dataURL").text(dataURL);
        $("#showDataURL").html('<img src="' + dataURL + '">');
      });
</script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Javascript图像裁剪器“ Croppie”进行保存

如何使用包含重定向的模拟网络服务器测试服务调用?

在网络服务器上存储私人图像的最佳实践

如何在网络服务器上上传图像。詹戈

如何在亚马逊网络服务器中迁移已部署的Laravel项目

Swift如何在UIImagepickercontroller中为编辑器设置编辑器裁剪大小

使用裁剪来裁剪图像而无需jquery

如何在我的网络服务器上运行python脚本?

使用jQuery进行垂直居中和裁剪图像

如何使我在Android上运行的网络服务器公开可用

使用网络服务的从属微调器

网络服务器上的Memcached

在网络服务器上存储多个大小的图像或调整当前图像的大小

在Yaws网络服务器上上传进度

如何在我的编辑器中获取带有灰色/棕褐色的裁剪图像?

如何在网络服务器上存储和组织上传的图像?

如何自定义Creative SDK图像编辑器中可用的裁剪选项

WordPress:如何在媒体编辑器中进行裁剪

亚马逊网络服务,如何开始

如何在端口 80 上运行气流网络服务器

如何查看 Apache 网络服务器上的当前连接?

亚马逊 AWS 网络服务器跨源请求

使用 jQuery 裁剪图像之前的文件类型验证

Javascript 在本地工作但不在网络服务器上。(未捕获的 ReferenceError:未定义 jQuery)

在网络服务器上查找使用邮件地址的系统用户 - Ubuntu

如何在flask网络服务器上检索数据作为文件对象?

如何将 Composer/npm 项目放到生产网络服务器上?

如何在我的网络服务器上使用 navigator 2.0 在 flutter web 中使用深层链接?

如何在公共网络服务器上拥有私有端点?