1

Below code crops the image after chosen from the local then provides a copy.

Is there a possible way to save the cropped image to MySQL as I have seen many articles but they use PHP for both server side and client side but as am using this to a mobile app where that allows JavaScript or Jquery in client side. And on server side am using PHP.

JSfiddel

HTML:

 <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 ng-src="{{myCroppedImage}}" /></div>
    </body>

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);
  });
7
  • 1
    There is no such thing as using php client side, browsers don't run php Commented Jul 11, 2015 at 13:14
  • @charlietfl this am not using this as a web app this is go in to b converted to a mobile application using phonegap. FYI: phone gap do not support php( that supports only HTML,CSS,JAVASCRITPS) ON CLIENT SIDE. Commented Jul 11, 2015 at 15:12
  • Hi Shaik, How did you solve this problem? Commented Aug 28, 2015 at 10:20
  • do you have any idea about this? Commented Aug 28, 2015 at 10:20
  • @vanarajcs sorry for late reply if you have not yet figured it out the first thing you have to do is let the user crop the image later the second image where the cropped is projected keep that in a hidden field pass that src to Mysql save is as a bloob and let me know if works Commented Sep 8, 2015 at 6:39

1 Answer 1

1

Try this.

 $data = json_decode(file_get_contents('php://input'), true);

 $img = str_replace('data:image/png;base64,', '', $data['img']);

 $img = str_replace(' ', '+', $img);

 $data = base64_decode($img);

 $file = "images/4.jpg";

 file_put_contents($file, $data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.