public ActionResult CropImage(FormCollection _vars) { string x = _vars["xaxis"]; string y = _vars["yaxis"]; string w = _vars["width"]; string h = _vars["height"]; string relativeFilename = _vars["filename"]; try { string fullOriginalPath = Server.MapPath(relativeFilename.Substring(0, relativeFilename.IndexOf("?ts"))); int nx, ny, nw, nh; using (System.Drawing.Image img = System.Drawing.Image.FromFile(fullOriginalPath)) { nw = ParseInt(w, img.Width); nh = ParseInt(h, img.Height); nx = ParseInt(x, 0); ny = ParseInt(y, 0); } using (System.Drawing.Image croppedImage = System.Drawing.Image.FromStream(WebTools.Crop(fullOriginalPath, nw, nh, nx, ny), true)) { string saveFileName = Path.GetFileName(fullOriginalPath); croppedImage.Save(fullOriginalPath, croppedImage.RawFormat); return(Json( new { }, "text/html")); } } catch (Exception e) { Response.StatusCode = 500; return(Json( new { exception = e.Message }, "text/html")); } }