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

getCroppedCanvas generate black image in Chrome after ready except if I had a timeout #303

Closed
3 tasks done
peterpeterparker opened this issue Feb 25, 2018 · 4 comments
Closed
3 tasks done
Labels

Comments

@peterpeterparker
Copy link

peterpeterparker commented Feb 25, 2018

I'm submitting a...

  • Support
  • Bug report

To be honest, I'm not sure if it's really a bug or just something I do wrong...

Current behavior

I'm chaining the creation of a new Cropper with creating a new image thru getCroppedCanvas().toDataURL when cropper is ready (see code below)

On iOS/Safari everything works like a charm.
Same code, on Android/Chrome, generate a black image.

After searching a solution, I discovered that adding a small 100ms timeout to the call solve the issue on Android/Chrome.

Expected behavior

I would be happy to not solve this by adding a delay.

Minimal reproduction of the problem with instructions

private crop() {
  this.cropper = new Cropper(imgURL, {
        viewMode: 2,
        aspectRatio: 1,
        dragMode: 'move',
        modal: true,
        guides: false,
        highlight: true,
        background: true,
        autoCrop: true,
        autoCropArea: 0.9,
        responsive: true,
        ready: (event: CropperReadyEvent) => {

            this.initFilterSrcImg();
        }
      });
 }
 
 private initFilterSrcImg() {
        let filterCropBox: CropBoxData = this.cropper.getCropBoxData();

        const filterWidth: number = 60;
        const filterHeight: number = filterCropBox.height * filterWidth / filterCropBox.width;

        this.croppedImgFilterSrc = this.cropper.getCroppedCanvas({
            width: filterWidth,
            height: filterHeight
        }).toDataURL('image/jpeg', 0.92);
}

If I encapsulate

            this.initFilterSrcImg();

with a timeout

            setTimeout(() => {
                this.initFilterSrcImg();
            }, 100);

then it works on Android too.

What is the motivation / use case for changing the behavior?

I create this miniature in order to present filters to my user, see video https://web-photo-filter.firebaseapp.com

Browser:

  • Chrome (Android) / Same on Android 7.1 and 8.1
@fengyuanchen
Copy link
Owner

Does this issue still exist with the latest version (v1.3.2 currently)?

@peterpeterparker
Copy link
Author

@fengyuanchen just tested again, yes I could definitely confirm that it still exist with latest version v1.3.2

@lfaoanl
Copy link

lfaoanl commented Apr 5, 2018

Same problem on Win10/Chrome

@peterpeterparker
Copy link
Author

@fengyuanchenI test v1.3.5 and could confirm it's now fixed, timeout workaround isn't needed anymore

thx!

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