/// <summary> /// Optimizes the image based on the settings in the arguments. /// </summary> public void OptimizeImage(int maxWidth, int maxHeight, int quality, bool toJpeg = true) { if (_FileData != null && _FileData.Length > 10) { var optimizer = new ImageOptimizer(maxWidth, maxHeight, quality); _FileData = optimizer.Optimize(_FileData, toJpeg); } }
public async Task OnPostUploadAsync() { if (IsImage(UploadedImageFile.FileName)) { string filename = UniqueFilename(UploadedImageFile.FileName); MemoryStream stream = new MemoryStream(); UploadedImageFile.CopyTo(stream); byte[] image = await ResizeImageBytes(stream.ToArray(), 1024, 1024); //make 1024x1024 the largest image size System.IO.File.WriteAllBytes(FileImageFolder + filename, image); imageOptimizer.Optimize(FileImageFolder + filename, logger); ImageListValue = filename; await OnPostSelectImageAsync(); } }
//// END DATALIST EVENTS //// //// BEGIN BUTTONS //// protected void btn_UserImage_Click(object sender, EventArgs e) { if (upl_userimage.HasFile) { var op = new ImageOptimizer(); op.ImgQuality = 80; op.MaxHeight = 150; op.MaxWidth = 150; Bitmap bmp = ResizeImage(upl_userimage.PostedFile.InputStream, 150, 150); bmp.Save(Server.MapPath("~/Images/Users/" + FetchUser.UserID() + "/user_defined.jpg"), ImageFormat.Jpeg); op.Optimize(Server.MapPath("~/Images/Users/" + FetchUser.UserID() + "/user_defined.jpg")); // Reload Page Response.Redirect("ManageOrg.aspx"); } }
public IActionResult ProductAdd(ProductViewModel model) { if (ModelState.IsValid) { Category category; category = categoryService.Get(x => x.id == model.Categoryid, CurrentLanguage.id); if (category == null && model.Categoryid == 0) { Category rootCategory = categoryService.Get(x => x.Name == "ROOT" && x.WebSite.id == CurrentWebsite.id, CurrentLanguage.id); if (rootCategory == null) { rootCategory = new Category() { Name = "ROOT", Parentid = 0, WebSite = CurrentWebsite, Language = CurrentLanguage, Priority = int.MaxValue }; categoryService.Add(rootCategory); categoryService.Save(); } category = rootCategory; } else if (category == null && model.Categoryid != 0) { ModelState.AddModelError("", "Girdiğiz kategori kimliği ile bir kategori bulunamadı"); return(View(model)); } string uniqueFileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "ProductImages"); uniqueFileName = Guid.NewGuid().ToString().Replace("-", "") + "_" + model.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Image.CopyTo(new FileStream(filePath, FileMode.Create)); imageOptimizer.Optimize(filePath, logger); } Product product = new Product() { SupTitle = model.SupTitle, SubTitle = model.SubTitle, Category = category, PhotoPath = uniqueFileName, Description = model.Description, MetaTags = model.MetaTags, Keywords = model.Keywords, Content = model.Content, Title = model.Title, CreateUserid = LoginUser.id, IsActive = model.IsActive, Language = CurrentLanguage, Priority = model.Priority }; productService.Add(product); productService.Save(); cacheService.Remove($"{CacheInfo.SubProducts}-{category.id}-{category.Languageid.Value}"); cacheService.Remove($"{CacheInfo.OrderedProducts}-{CurrentWebsite.id}-{CurrentLanguage.id}"); } return(RedirectToAction("ProductAdd", "Pages", new { area = "Admin" })); }