cstefanache / angular2-img-cropper

Angular 2 Image Cropper
MIT License
364 stars 135 forks source link

How to store cropped image in a string variable #159

Closed Seeker93 closed 7 years ago

Seeker93 commented 7 years ago

Hey

I was wondering how you would store the cropped image as a base64 string in a variable. Here's my fileChangeListener code:

`fileChangeListener($event) {
    var image:any = new Image();
    var file:File = $event.target.files[0];
    var myReader:FileReader = new FileReader();
    var that = this;
    var imageResult:string;

    myReader.onloadend = function (loadEvent:any) {
        image.src = loadEvent.target.result;
        imageResult = image.src;
        that.employee.binaryPhoto =image.src+"";

    };

  myReader.readAsDataURL(file);

    }`

This code populates the employee object's binaryPhoto property with the base64 image string. However, this is the image string for the original uploaded image. How do I store the base64 string for the cropped image?

oztek22 commented 7 years ago

loadEvent.target.result will give you the Image in base64 format.

cstefanache commented 7 years ago

Closing. thanks @oztek22