Example #1
0
        private string CropAvatar(string sourcePath, int x, int y, int w, int h)
        {
            var savePath = sourcePath.Replace("tmp_", "");

            ImageUntils.CropImage(Server.MapPath(sourcePath), Server.MapPath(savePath), new Rectangle(x, y, w, h));
            FileUntils.Delete(Server.MapPath(sourcePath));
            return(savePath);
        }
Example #2
0
        public ActionResult UploadAvatar(string id)
        {
            var files = Request.Files;

            if (files.Count > 0)
            {
                var imgFile    = files[0];
                var ext        = Path.GetExtension(imgFile.FileName);
                var dirName    = "/webupload/avatar/";
                var savePath   = dirName + string.Format("avatar_tmp_{0}{1}", id, ext);
                var physicPath = Server.MapPath(savePath);
                FileUntils.CreateDirIfNotExists(Server.MapPath(dirName));
                imgFile.SaveAs(physicPath);
                return(Json(new { success = true, savePath = savePath }));
            }
            return(Json(new { success = false, savePath = string.Empty }));
        }