Hi i want to crop the image and upload it on server.
i am using croppie js plugins and use get() method to get points to crop it on server by using WebImage class.
Asp.net MVC code
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ImageCrop(FormCollection fc)
{
WebImage data = WebImage.GetImageFromRequest();
if (data != null)
{
int x1, y1, x2, y2;
x1 = int.Parse(fc["x1"].ToString());
y1 = int.Parse(fc["y1"].ToString());
x2 = int.Parse(fc["x2"].ToString());
y2 = int.Parse(fc["y2"].ToString());
var fileName = Path.GetFileName(data.FileName);
fileName = Lawyer_id2 + ".jpeg";
var big = Server.MapPath("~/contents/ProfilePictures/big/" + fileName);
data.Crop(y1, x1, x2, y2);
data.Save(big);
}
}
Js code
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 200,
height: 200,
type: 'square'
},
boundary: {
width: 300,
height: 300
},
showZoomer: false,
mouseWheelZoom: false
});
readFile(fl);
$(".closeModal").on("click", function () {
$uploadCrop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function (resp) {
$('.upload-msg').css('display', '');
popupResult({
src: resp
});
});
var arr = $uploadCrop.croppie('get').points;
$("#x1").val(arr[0]);
$("#y1").val(arr[1]);
$("#x2").val(arr[2]);
$("#y2").val(arr[3]);
});
I get all points in hidden input fields and then pass this points to webimge objects to crop but problem is that the cropped image not maintain the aspect ratio and cropped wrongly, browser side cropping is perfect but when i pass that points to server side for cropping it not works like browser side and i have no clue to solve this.
result-image: foliotek.com/devblog/…