Cropper: Get Cropped image

Created on 26 Jun 2015  路  4Comments  路  Source: fengyuanchen/cropper

How can i get cropped image to display in img ? Can u give sample code.

Thank You.

Most helpful comment

It return the Canvas element. With canvas you can extract the image data with toDataURL() method.
Do this test:

var imageData = $('img').cropper('getCroppedCanvas').toDataURL();
$('<img>').attr('src', imageData).appendTo('body');

All 4 comments

$('img').cropper('getCroppedCanvas');

or

$('img').cropper('getCroppedCanvas', {width: 100, height: 100});

it only return :

<canvas width="200" height="200"></canvas>

it don't show image.

It return the Canvas element. With canvas you can extract the image data with toDataURL() method.
Do this test:

var imageData = $('img').cropper('getCroppedCanvas').toDataURL();
$('<img>').attr('src', imageData).appendTo('body');

I was facing an issue when I was ruing code as an html file, issue was

cropper-in-modal-Rauf.html:110 Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
image

Found solution here:
https://stackoverflow.com/a/22716873/2114413

Now I can show results in preview image

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zilions picture zilions  路  3Comments

jzahka picture jzahka  路  4Comments

jloguercio picture jloguercio  路  6Comments

rajjanorkar picture rajjanorkar  路  4Comments

nchase picture nchase  路  5Comments