cstefanache / angular2-img-cropper

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

Image isn't cropped automatically when noFileInput is set to true. #38

Closed cleever closed 8 years ago

cleever commented 8 years ago

In sample punkler is possible to reproduce the issue:

https://embed.plnkr.co/V91mKCNkBQZB5QO2MUP4/

When I use the integrated file input, the cropped img is set automatically.

When I use the sample cropper 2, the cropped img is only set if I move the cursor.

joerex commented 8 years ago

The setImage function in ImageCropperComponent needs to be changed to this:

setImage(image) {
    this.cropper.setImage(image);
    this.image.original = image;
    this.image.image = that.cropper.getCroppedImage().src;
    this.onCrop.emit(that.cropper.getCropBounds());
}

then you could also change the fileChangeListener function to:

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

        fileReader.onloadend = function (loadEvent:any) {
            image.src = loadEvent.target.result;
            that.setImage(image);
        };

        fileReader.readAsDataURL(file);
}
cstefanache commented 8 years ago

Fixed. Thanks @joerex - will be released on 0.6