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

Created on 25 Jul 2017  路  2Comments  路  Source: fengyuanchen/cropper

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?

Most helpful comment

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

All 2 comments

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steefaan picture steefaan  路  6Comments

Kendokai picture Kendokai  路  4Comments

ThameDBA picture ThameDBA  路  4Comments

zilions picture zilions  路  3Comments

ghengeveld picture ghengeveld  路  3Comments