Beispiel #1
0
        public static ImagePaths SaveThumbnail(string originalImagePath, int thumbSize = DEFAULT_THUMB_SIZE, int imgQuality = 95)
        {
            var origImg = new KalikoImage(originalImagePath);

            //Create thumbnail name from original image name
            //var ext = Path.GetExtension(originalImagePath);
            //var imgWOExt = Path.GetFileNameWithoutExtension(originalImagePath);
            var newThumbName = GetUniqueFileName(originalImagePath, "thumb");// String.Format("{0}_thumb.{1}", imgWOExt, ext);

            //var origFileName = Path.GetFileName(originalImagePath);

            var newThumbPath = GetNewFullPath(originalImagePath, newThumbName); // originalImagePath.Replace(origFileName, newThumbName);

            var splitPath = originalImagePath.Split(@"\".ToCharArray());
            var unixStyleFolderPortion = new StringBuilder();
            for (var i = 0; i < splitPath.Length; i++)
            {
                if (i == 0) { continue; } //We don't want the drive letter
                if (i == splitPath.Length - 1) { break; } //we don't want the fileName either
                unixStyleFolderPortion.AppendFormat("{0}/", splitPath[i]);  //we just need the folder paths
            }

            var dateFolder = splitPath[splitPath.Length - 2];

            origImg.GetThumbnailImage(thumbSize, thumbSize, ThumbnailMethod.Crop).SavePNG(newThumbPath, imgQuality);
            //var webAddress = String.Concat(ConfigurationManager.AppSettings["BaseDomain"], unixStyleFolderPortion.ToString(), newThumbName);
            //var webAddress = String.Concat(ConfigurationManager.AppSettings["BaseDomain"], "Uploads/", dateFolder, slash, newThumbName);
            var webAddress = String.Concat(ConfigurationManager.AppSettings["BaseDomain"], "Uploads/", newThumbName);
            //var sqlAddress = String.Format("{0}{1}", unixStyleFolderPortion.ToString(), newThumbName);
            //var sqlAddress = String.Format("Uploads/{0}{1}{2}", dateFolder, slash, newThumbName);
            var sqlAddress = String.Format("Uploads/{0}", newThumbName);

            var paths = new ImagePaths(webAddress, sqlAddress, newThumbPath);

            return paths;
        }
Beispiel #2
0
        private ImagePaths SaveUploadedFile(HttpPostedFileBase fileUpload)
        {
            var dateFolderPath = ImageHandler.GetDatedFolderPath();
            var fileName = String.Concat(dateFolderPath, "_", Guid.NewGuid().ToString().Replace("-", ""), Path.GetExtension(fileUpload.FileName));
            var pngFileName = String.Concat(dateFolderPath, "_", Guid.NewGuid().ToString().Replace("-", ""), ".png");
            var uploadFolder = String.Concat(AppDomain.CurrentDomain.BaseDirectory, @"Uploads\");
            //var uploadFolder = String.Concat(AppDomain.CurrentDomain.BaseDirectory, @"Uploads\", dateFolderPath, slash);
            //if (!Directory.Exists(uploadFolder))
            //{
            //    Directory.CreateDirectory(uploadFolder);
            //}
            var fullSavePath = Path.Combine(uploadFolder, fileName);
            fileUpload.SaveAs(fullSavePath);

            var pngFullImagePath = this.ConvertUploadedImageToPng(fullSavePath, pngFileName);
            //Use Web Address later
            //var webAddress = String.Concat(ConfigurationManager.AppSettings["BaseDomain"], "Uploads/", dateFolderPath, slash, fileName);
            //var sqlAddress = String.Format("Uploads/{0}{1}{2}", dateFolderPath, slash, fileName);
            var webAddress = String.Concat(ConfigurationManager.AppSettings["BaseDomain"], "Uploads/", pngFileName);
            var sqlAddress = String.Format("Uploads/{0}", pngFileName);

            var paths = new ImagePaths(webAddress, sqlAddress, pngFullImagePath);
            return paths;
            //return Tuple.Create(webAddress, sqlAddress);
        }
Beispiel #3
0
        private static ImagePaths SaveImage(string fullFilePath, string uniqueFileName, Bitmap image)
        {
            var uploadFolder = GetFolderPathWithoutDriveLetter(fullFilePath);

            if (File.Exists(fullFilePath))
            {
                //try
                //{
                File.Delete(fullFilePath);

                //}catch(Exception e)
                //{
                //    System.GC.Collect();
                //    System.GC.WaitForPendingFinalizers();
                //}
                //if (File.Exists(fullFilePath))
                //{
                //    try
                //    {
                //        File.Delete(fullFilePath);
                //    }
                //    catch (Exception)
                //    {

                //    }
                //}
            }

            image.Save(fullFilePath); //Save Image

            //Use Web Address later
            var webAddress = String.Concat(ConfigurationManager.AppSettings["BaseDomain"], uploadFolder, uniqueFileName);
            var sqlAddress = String.Format("{0}{1}", uploadFolder, uniqueFileName);

            var paths = new ImagePaths(webAddress, sqlAddress, fullFilePath);
            return paths;
        }