Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to export the cropped image #3

Closed
ahsanaasim opened this issue Sep 27, 2017 · 11 comments
Closed

How to export the cropped image #3

ahsanaasim opened this issue Sep 27, 2017 · 11 comments
Labels

Comments

@ahsanaasim
Copy link

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
Copy link
Owner

matheusdavidson commented Sep 27, 2017

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
Copy link
Author

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
Copy link
Owner

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

@matheusdavidson
Copy link
Owner

see this: fengyuanchen/cropper#119

@ahsanaasim
Copy link
Author

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

@matheusdavidson
Copy link
Owner

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

@ahsanaasim
Copy link
Author

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

@ahsanaasim
Copy link
Author

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

@matheusdavidson
Copy link
Owner

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

@Coolhat1177
Copy link

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

@matheusdavidson
Copy link
Owner

@Coolhat1177, please open a new issue with this bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants