Ejemplo n.º 1
0
        public ActionResult Upload(ProfileViewModel model)
        {
            var image = WebImage.GetImageFromRequest();
            if (image != null)
            {

                var filename = Path.GetFileName(image.FileName);
                var name = image.FileName;
                image.Save(Path.Combine(HttpContext.Server.MapPath("/Images"), filename));
                filename = Path.Combine(HttpContext.Server.MapPath("/Images"), filename);
                model.ImageUrl = Url.Content(filename);
                model.ImageUrl = name;

                var editModel = new EditorInputModel()
                {
                    Profile = model,
                    Width = image.Width,
                    Height = image.Height,
                    Top = image.Height * 0.1,
                    Left = image.Width * 0.9,
                    Right = image.Width * 0.9,
                    Bottom = image.Height * 0.9
                };
                return View("Edit", editModel);
            }
            return View("Index", model);
        }
Ejemplo n.º 2
0
        public ActionResult EditImage(EditorInputModel editor)
        {
            string fileName = editor.Profile.ImageUrl;
            var image = new WebImage(HttpContext.Server.MapPath("/Images/Temp/") + fileName);

            double ratio = editor.Width / 620;
            //the values to crop off.
            double top = editor.Top * ratio;
            double left = editor.Left * ratio;
            double bottom = editor.Height - editor.Bottom * ratio;
            double right = editor.Width - editor.Right * ratio;

            image.Crop((int)top, (int)left, (int)bottom, (int)right);

            //the image size I need at the end
            image.Resize(620, 280);
            image.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News"), fileName));
            System.IO.File.Delete(Path.Combine(HttpContext.Server.MapPath("/Images/Temp/"), fileName));

            var imageThumb = image;
            imageThumb.Resize(65, 50);
            imageThumb.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News/Thumb"), fileName));
            editor.Profile.ImageUrl = fileName;
            return View("Index", editor.Profile);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(EditorInputModel editor)
        {
            string fileName = editor.Profile.ImageUrl;
            Console.WriteLine("test");
            var image = new WebImage(HttpContext.Server.MapPath("/Images/") + fileName);
            //the values to crop off.
            double top = editor.Top;
            double left = editor.Left;
            double bottom = editor.Bottom;
            double right = editor.Right;

            image.Crop((int)top, (int)left, (int)bottom, (int)right);

            //the image size I wanted
            image.Resize(620, 280);
            image.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News"), fileName));
            System.IO.File.Delete(Path.Combine(HttpContext.Server.MapPath("/Images/"), fileName));
            editor.Profile.ImageUrl = fileName;
            return View("Index", editor.Profile);
        }
Ejemplo n.º 4
0
        public ActionResult UploadImage(ProfileViewModel model, string ImageName)
        {
            var image = WebImage.GetImageFromRequest();
            if (image != null)
            {
                var filename = ImageName + ".png";
                image.Save(Path.Combine(HttpContext.Server.MapPath("/Images/Temp"), filename));
                model.ImageUrl = filename;

                var editModel = new EditorInputModel()
                {
                    Profile = model,
                    Width = image.Width,
                    Height = image.Height,
                    Top = image.Height * 0.1,
                    Left = image.Width * 0.9,
                    Right = image.Width * 0.9,
                    Bottom = image.Height * 0.9
                };
                return View("EditImage", editModel);
            }
            return View("Index", model);
        }