public ActionResult Upload(int photoAlbumId, IEnumerable<HttpPostedFileBase> images) { if (images != null && images.All(i => i != null)) { foreach (var image in images) { var webImage = new WebImage(image.InputStream) { FileName = image.FileName }; webImage = webImage.AddImageWatermark("~/Content/Images/Watermark96.png"); ImagesManager.UploadImage(webImage, Path.Combine("PhotoAlbum", photoAlbumId.ToString()), true, 120, 120, true); } TempData["Result"] = Resource.ChangesSaved; } else { TempData["Result"] = Resource.NoImagesChosen; } return RedirectToAction("Details", "PhotoAlbum", new { id = photoAlbumId }); }
public ActionResult Index(HttpPostedFileBase arquivo) { if (ModelState.IsValid) { if (arquivo != null) { if (arquivo.ContentLength > (1024 * 1024)) { ModelState.AddModelError("arquivo", "O tamanho do arquivo não pode ser maior que 1Mb"); return View(); } var supportedTypes = new[] { "jpg", "jpeg", "png" }; var fileExt = Path.GetExtension(arquivo.FileName).Substring(1); if (!supportedTypes.Contains(fileExt.ToLower())) { ModelState.AddModelError("arquivo", "Tipo de arquivo invalido, use somente arquivos jpg, jpeg ou png"); return View(); } //var fileName = Path.GetFileName(arquivo.FileName);//Nome Original do arquivo var fileName = Guid.NewGuid().ToString() + "." + fileExt;//Nome unico var path = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName); //arquivo.SaveAs(path); //somente se não for editar a foto, como no codigo abaixo WebImage imagem = new WebImage(arquivo.InputStream); imagem.Resize(350, 350); //imagem.AddTextWatermark("Cleyton Ferrari"); imagem.AddImageWatermark("Content/Uploads/logo.png", 50, 50, "Right", "Bottom", 50, 2); //imagem.Crop(100, 100, 100, 100); imagem.FlipHorizontal(); imagem.Save(path); ViewBag.imagem = "Content/Uploads/" + fileName; } } return View(); }
private ActionResult GetFileInternal(string type, string url, int width = 0, int height = 0) { url = url.Replace("/", "/"); if (!this._fileService.CheckAccessFile(url)) { this.Response.StatusCode = 401; return new HttpUnauthorizedResult(); } string path = null; if (width > 0 && height > 0) { path = this._imageConverter.GetThumbPath(url, width, height); var pathParts = path.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries); url = pathParts.Last(); path = string.Format("/{0}/", Web.Helpers.GetVirtualPath(string.Join("\\", pathParts.Take(pathParts.Length - 1)))); } else { path = this.Request.Url.Segments.Contains(string.Format("{0}/", CmsConstants.SECURE)) ? string.Format("~/Content/{0}/{1}/", type, CmsConstants.SECURE) : string.Format("~/Content/{0}/", type); } // Todo: logic te determine which images should be watermarked. Use an event? if (false) { var webImage = new WebImage(path); string waterMarkPath = string.Format("{0}{1}", Server.MapPath("~"), StrixCms.Config.Files.WaterMarkPath.Replace('/', '\\')); webImage.AddImageWatermark(waterMarkPath); return this.File(webImage.GetBytes(), MimeMapping.GetMimeMapping(url)); } return this.File(this.Server.MapPath(path) + url, MimeMapping.GetMimeMapping(url)); }
public static void Logo(string name, string diretorio, List<PosicaoLogo> posicaoLogo) { if (posicaoLogo.Any()) { var pathImagem = MontaPath(diretorio, name); var imagem = new WebImage(pathImagem); foreach (var pLogo in posicaoLogo) { //Todo: Tirar o acesso ao bando daqui var nomeLogo = Fabrica.LogoAplicacaoMongo().ListarPorId(pLogo.IdLogo).Imagem; //Carrega o logo e redimenciona para 33% do tamanho da imagem var logo = new WebImage(MontaPath("Logo", nomeLogo)).Resize(imagem.Width / 3, imagem.Height / 3); imagem.AddImageWatermark(logo, logo.Width, logo.Height, pLogo.PosicaoHorizontal, pLogo.PosicaoVertical, 90, 0); } imagem.Save(pathImagem); } }