Ajax通过向PHP创建canvas(BLOB)来发送裁剪图像

时间:2015-07-16 08:41:27

标签: javascript php jquery ajax canvas

我正在尝试将id =“send_to_db”图像转换为画布形式并发送到php我已经谷歌搜索alto但是对于颗粒裁剪图像我dint找到任何使用完整代码,有没有办法转换后的图像被裁剪并显示在图像上,该微粒图像创建一个blob形式并通过ajax发送到php FIDDEL:EXAMPLE
JS:

angular.module('app', ['ngImgCrop'])
  .controller('Ctrl', function($scope) {
    $scope.myImage='';
    $scope.myCroppedImage='';

    var handleFileSelect=function(evt) {
      var file=evt.currentTarget.files[0];
      var reader = new FileReader();
      reader.onload = function (evt) {
        $scope.$apply(function($scope){
          $scope.myImage=evt.target.result;
        });
      };
      reader.readAsDataURL(file);
    };
    angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
  });

CSS:

.cropArea {
  background: #E4E4E4;
  overflow: hidden;
  width:500px;
  height:350px;
}

HTML:

<link href="https://cdn.rawgit.com/alexk111/ngImgCrop/master/compile/minified/ng-img-crop.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>



<body ng-app="app" ng-controller="Ctrl">
  <div>Select an image file: <input type="file" id="fileInput" /></div>
  <div class="cropArea">
    <img-crop image="myImage" result-image="myCroppedImage"></img-crop>
  </div>
  <div>Cropped Image:</div>
  <div><img id="send_to_db" ng-src="{{myCroppedImage}}" /></div>
</body>

0 个答案:

没有答案