private string FileCropExecution(IFormFile file, string uploadPath, string fileExtension) { try { string filename = MediaHelper.NewFileName(file.FileName.ToLower(), uploadPath); string tempPath = uploadPath; if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } tempPath = Path.Combine(tempPath, filename); using (FileStream tempPath1 = System.IO.File.Create(tempPath)) file.CopyTo(tempPath1); ImageOptimize objOptimizeImage = new ImageOptimize(); List <MediaThubnailInfo> lst = objOptimizeImage.GetStandardThubnails(uploadPath, filename); foreach (var p in lst) { if (!Directory.Exists(p.SavePath)) { Directory.CreateDirectory(p.SavePath); } } objOptimizeImage.OptimizeImage(tempPath, false, fileExtension, lst); return(filename); } catch { throw; } }
public static int DownloadAndSaveImage(string rootPath, string downloadUrl, string downLoadPath) { int result = 0; string orginalPath = string.Empty; string thumbLargePath = string.Empty; string thumbMediumPath = string.Empty; string baseLocationPath = string.Empty; string strTempLocation = string.Empty; try { baseLocationPath = serverRootPath + downLoadPath + "/"; orginalPath = serverRootPath + originalThumbPath + downLoadPath + "/"; thumbLargePath = serverRootPath + largeThumbPath + downLoadPath + "/"; thumbMediumPath = serverRootPath + mediumThumbPath + downLoadPath + "/"; strTempLocation = serverRootPath + tempThumbPath + downLoadPath + "/"; if (!Directory.Exists(orginalPath)) { Directory.CreateDirectory(orginalPath); } if (!Directory.Exists(thumbLargePath)) { Directory.CreateDirectory(thumbLargePath); } if (!Directory.Exists(thumbMediumPath)) { Directory.CreateDirectory(thumbMediumPath); } if (!Directory.Exists(baseLocationPath)) { Directory.CreateDirectory(baseLocationPath); } if (!Directory.Exists(strTempLocation)) { Directory.CreateDirectory(strTempLocation); } string currentDateTime = DateTime.Now.ToString().Replace('/', '_').Replace(':', '_').Replace(' ', '_'); var fileName = "Dload_" + currentDateTime + ".jpeg"; strTempLocation += fileName; using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(downloadUrl), strTempLocation); result = 1; } ImageOptimize objOptimizeImage = new ImageOptimize(); objOptimizeImage.OptimizeImage(rootPath, strTempLocation, downLoadPath + "/", fileName, Path.GetExtension(fileName).Replace(".", "")); } catch (Exception) { throw; } return(result); }