tinycrop icon indicating copy to clipboard operation
tinycrop copied to clipboard

Saving cropped image

Open hyperking opened this issue 4 years ago • 3 comments

Docs are missing directions for saving the cropped region. I would assume doing the following during the callback for any event listener but I'm not sure.

crop.on('end', function (region) { 
var canvas = document.getElementById('canvas');
var ctx = canvass.getContext('2d');
var image = document.querySelector('#edit-image img');

ctxs.drawImage(images, region.x, region.y, region.width, region.height);
});

hyperking avatar Dec 15 '19 16:12 hyperking

The same problem over here... wondering how to display only the cropped region to another .

mhsteppan avatar Sep 17 '20 22:09 mhsteppan

How do I save the cropped image? any suggestions for a different and simple library?

ronytesler avatar Nov 10 '20 00:11 ronytesler

idk all if you have solved your problem but I could reach to the solution with this code:

I have a canvas element with canvas id in the HTML file.

crop.on('end', function (region) { 
                canvas = document.getElementById('canvas');
                ctx = canvas.getContext('2d');
                image = new Image(); // Using optional size for image
                image.onload = drawImageActualSize; // Draw when image has loaded
                // Load an image of intrinsic size 300x227 in CSS pixels
                image.src = 'images/test.JPG';
                function drawImageActualSize() {
                    // Use the intrinsic size of image in CSS pixels for the canvas element
    canvas.width = region.width;
                    canvas.height = region.height;
                    // To use the custom size we'll have to specify the scale parameters
                    // using the element's width and height properties - lets draw one
                    // on top in the corner:
                    ctx.drawImage(this, region.x, region.y, region.width, region.height, 0, 0, region.width, region.height);
   
                }
}

For more information: MDN rendering image

a0m0rajab avatar Apr 23 '21 02:04 a0m0rajab