fengyuanchen / cropper

⚠️ [Deprecated] No longer maintained, please use https://github.com/fengyuanchen/jquery-cropper
MIT License
7.75k stars 1.74k forks source link

canvas.getDataUrl() is not a function. So can't extract base64 encoded string. #911

Closed mnori closed 7 years ago

mnori commented 7 years ago

Tested on v3.0.0-rc.3 with latest jquery.

Let's say I want to get the base64 encoded version of the cropped image. I need to use this method rather than the canvas.toBlob() approach, due to lack of IE9 compatibility for toBlob().

I first do the following:

var canvas = $("#cropper-image").cropper("getCroppedCanvas");
console.log(canvas);

Which produces (as expected):

<canvas width="319" height="319">

Now I attempt to convert to base64 using the following:

var data =  canvas.toDataUrl("image/jpeg");
console.log(data);

An error is thrown:

(index):60 Uncaught TypeError: canvas.toDataUrl is not a function
    at HTMLAnchorElement.<anonymous> ((index):60)
    at HTMLAnchorElement.dispatch (jquery-3.2.1.min.js:3)
    at HTMLAnchorElement.q.handle (jquery-3.2.1.min.js:3)

Is this a library bug, or am I doing something wrong?

mnori commented 7 years ago

I did a stupid. Should have called getDataURL(), not getDataUrl(). Doh!

coffeeeeee commented 4 years ago

toDataURL not get, if someone stuck here like me...