-
Notifications
You must be signed in to change notification settings - Fork 91
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
How to upload cropped image? #32
Comments
Croppr.js doesn't actually crop the images, it can relay the x, y, width and height of the cropped area to your server. On the server side you can then crop the uploaded images with php/node.js or whatever is suitable. |
Alternatively you can crop the image on the client side using a canvas. Something like this. const sourceImage = document.getElementById("sourceImage");
const croppr = new Croppr(sourceImage, {});
// When finished cropping
const cropRect = croppr.getValue();
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
canvas.width = cropRect.width;
canvas.height = cropRect.height;
context.drawImage(
croppr.imageEl,
cropRect.x,
cropRect.y,
cropRect.width,
cropRect.height,
0,
0,
canvas.width,
canvas.height,
);
const destinationImage = document.getElementById("destinationImage");
destinationImage.src = canvas.toDataURL(); You can do whatever you want with the data url, such as put it in a hidden field or send it to the server over an AJAX request. |
Adding to the code ryanb posted (thank you very much), you can also attach the cropped image to a regular
|
I'm able to crop images on the client side using this library, but how do I upload the cropped images to the server and then display that cropped image to the client?
The text was updated successfully, but these errors were encountered: