public static void SaveResizedImage(string filePath, string fileName, string resizedFileName, int width, int height) //resize by fixed dimenstion { Image origImg = Image.FromFile(Path.Combine(filePath, fileName)); Image resizedImg = FixedSize(origImg, width, height); string fileExt = FileProcessor.GetFileExtension(fileName); switch (fileExt) { case ".png": resizedImg.Save(Path.Combine(filePath, resizedFileName), ImageFormat.Png); break; case ".jpg": resizedImg.Save(Path.Combine(filePath, resizedFileName), ImageFormat.Jpeg); break; case ".jepg": resizedImg.Save(Path.Combine(filePath, resizedFileName), ImageFormat.Jpeg); break; case ".gif": resizedImg.Save(Path.Combine(filePath, resizedFileName), ImageFormat.Gif); break; default: break; } resizedImg.Dispose(); origImg.Dispose(); }
public void Upload(HttpPostedFile myFile, string destinationPath)//, int s_fileWidth, int s_fileHeight, string destinationFileName) { if (myFile != null) { string fileName = myFile.FileName; string fileExtenstion = FileProcessor.GetFileExtension(fileName); if (myFile.ContentLength > 0 && myFile.ContentLength < 10 * 1024 * 1024) { if (fileExtenstion == ".jpg" || fileExtenstion == ".jepg" || fileExtenstion == ".png" || fileExtenstion == ".gif") { //~/Content/Assets/Images/ //string path = Path.Combine(HttpContext.Current.Server.MapPath(destinationPath), Path.GetFileName(myFile.FileName)); //string picPath = Path.Combine(destinationPath, myFile.FileName); ////string extension = FileProcessor.GetFileExtension(file.FileName); //string purePath = HttpContext.Current.Server.MapPath(destinationPath); myFile.SaveAs(destinationPath); //Image img = Image.FromFile(path); //string newFileName = user.UserProfile.FirstName + "_" + user.UserProfile.LastName + // fileExtenstion; //if (img.Width > s_fileWidth || img.Height > s_fileHeight) //{ // //resize image // // // ImageProcessor.SaveResizedImage(purePath, fileName, destinationFileName, s_fileWidth, s_fileHeight); //} //if (img.Width > l_fileWidth || img.Height > l_fileHeight) //{ // //resize image // // // ImageProcessor.SaveResizedImage(purePath, fileName, destinationFileName, l_fileWidth, l_fileHeight); //} } } } }