matheusdavidson / angular-cropperjs

CropperJS integration for Angular +6
MIT License
109 stars 68 forks source link

How to export the cropped image #3

Closed ahsanaasim closed 7 years ago

ahsanaasim commented 7 years ago

I can see an export eventEmitter for the cropper. But not sure how to use it. Can you post an example about how to export the cropped image as blob & base64 data?

matheusdavidson commented 7 years ago

Hi there, thank you for posting your question.

You need to follow the readme.md, there is a part showing how to use cropperjs methods:

Using CropperJS methods:

Use @ViewChild in your component to get the element:

In your app.component.html

<angular-cropper #angularCropper ..>

And in your app.component.ts


//
// Import AngularCropperjsComponent
import { AngularCropperjsComponent } from 'angular-cropperjs';

//
// Get with @ViewChild
@ViewChild('angularCropper') public angularCropper: AngularCropperjsComponent;

Then just call the CropperJS method you want:

anywhere in your app.component.ts


//
// Get base64
this.angularCropper.cropper.getCroppedCanvas().toBlob((blob) =>{
    // blob is your base64..
});
ahsanaasim commented 7 years ago

Thanks for the reply.

I tried this code before but getting this error

Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported.

screen shot 2017-09-28 at 1 57 34 pm

matheusdavidson commented 7 years ago

Are you using checkCrossOrigin? you need to use it otherwise toBlob won't work.

matheusdavidson commented 7 years ago

see this: https://github.com/fengyuanchen/cropper/issues/119

ahsanaasim commented 7 years ago

this is what i used for cropperOptions this.angularCropper.cropperOptions = { checkCrossOrigin: false, };

matheusdavidson commented 7 years ago

Remove checkCrossOrigin(it default to true), leave the config empty {} for now and it will work

ahsanaasim commented 7 years ago

But problem is my image is coming from a separate domain that. So i needed to set checkCrossOrigin to false;

ahsanaasim commented 7 years ago

I solved the problem by allowing cors from server end. Thanks

matheusdavidson commented 7 years ago

Good to hear, unfortunately that is a security limilation of the browser, not the plugin.

Coolhat1177 commented 6 years ago

node_modules/angular-cropperjs/angular-cropperjs"' has no exported member 'AngularCropperjsComponent'. why this error is coming

matheusdavidson commented 6 years ago

@Coolhat1177, please open a new issue with this bug