Пример #1
0
        /// <summary>
        /// Copies image file to the destination.The destination need not have the file but the destination must add the original file name in its path
        /// </summary>
        /// <param name="rs">The resize setting</param>
        /// <param name="SourceFile">The original image file</param>
        /// <param name="DestinationFolder">The path of the destination folder including the filename same as original image file</param>
        public static void copyOriginalImageToRespectives(ResizeSettings rs, string SourceFile, string DestinationFolder, AspxCommonInfo aspxCommonObj, IsWaterMark isWaterMark)
        {
            // string combinedPath = Path.Combine(SourceFolder, filename);

            if (isWaterMark.ToString() == "True")
            {
                //ResizeSettings settingObj =
                ApplyWaterMarkToImage(aspxCommonObj, rs, SourceFile, DestinationFolder);
            }
            else
            {
                using (FileStream fileStream = new FileStream(SourceFile, FileMode.Open))
                {
                    ImageJob i = new ImageJob(fileStream, DestinationFolder, new Instructions(rs));
                    i.CreateParentDirectory = false;     //Auto-create the uploads directory.
                    i.Build();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Builds the image dynamically based upon the store setting sizes call this before giving image source
        /// </summary>
        /// <param name="imageFile">Name of the image as in db</param>
        /// <param name="type">Type could be small,medium or large based on front-end requirement</param>
        /// <param name="aspxCommonObj"></param>
        public static void ImageBuilder(string imageFile, ImageType type, ImageCategoryType imgCategory, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                string      filename          = imageFile;
                bool        isExistImage      = false;
                string      sourceFolder      = string.Empty;
                string      imgDestintionloc  = string.Empty;
                string      imageSourceloc    = string.Empty;
                string      destinationFolder = string.Empty;
                IsWaterMark isWM = IsWaterMark.False;
                if (imgCategory == ImageCategoryType.Item)
                {
                    sourceFolder     = StrRootPath + @"Modules\AspxCommerce\AspxItemsManagement\uploads\" + @"" + filename + "";
                    imgDestintionloc = StrRootPath + @"Modules\AspxCommerce\AspxItemsManagement\uploads\";
                    imageSourceloc   = StrRootPath + @"Modules\AspxCommerce\AspxItemsManagement\uploads\";
                    isWM             = IsWaterMark.True;
                }
                else if (imgCategory == ImageCategoryType.Brand)
                {
                    sourceFolder     = StrRootPath + @"Modules\AspxCommerce\AspxBrandManagement\uploads\" + @"" + filename + "";
                    imgDestintionloc = StrRootPath + @"Modules\AspxCommerce\AspxBrandManagement\uploads\";
                    imageSourceloc   = StrRootPath + @"Modules\AspxCommerce\AspxBrandManagement\uploads\";
                    isWM             = IsWaterMark.False;
                }
                else if (imgCategory == ImageCategoryType.Category)
                {
                    sourceFolder     = StrRootPath + @"Modules\AspxCommerce\AspxCategoryManagement\uploads\" + @"" + filename + "";
                    imgDestintionloc = StrRootPath + @"Modules\AspxCommerce\AspxCategoryManagement\uploads\";
                    imageSourceloc   = StrRootPath + @"Modules\AspxCommerce\AspxCategoryManagement\uploads\";
                    isWM             = IsWaterMark.False;
                }
                ResizeSettings resizeSetings = new ResizeSettings();
                resizeSetings.Format  = "jpg";
                resizeSetings.Mode    = FitMode.Carve;
                resizeSetings.Scale   = ScaleMode.Both;
                resizeSetings.Quality = 75;

                switch (type)
                {
                case ImageType.Large:
                {
                    string imgFolder = imageSourceloc + @"" + type + "";
                    destinationFolder = imgDestintionloc + @"" + type + @"\" + filename + "";
                    isExistImage      = CheckIfImageExists(filename, imgFolder);
                    if (!(isExistImage))
                    {
                        ImageSettings imgStng = new ImageSettings(aspxCommonObj);
                        if (Convert.ToBoolean(imgStng.ResizeImagesProportionally) == true)
                        {
                            resizeSetings.Width = imgStng.ItemLargeThumbNailWidth;
                        }
                        else
                        {
                            resizeSetings.Width  = imgStng.ItemLargeThumbNailWidth;
                            resizeSetings.Height = imgStng.ItemLargeThumbNailHeight;
                        }
                        copyOriginalImageToRespectives(resizeSetings, sourceFolder, destinationFolder, aspxCommonObj, isWM);
                    }
                    break;
                }

                case ImageType.Medium:
                {
                    string imgFolder = imageSourceloc + @"" + type + "";
                    destinationFolder = imgDestintionloc + @"" + type + @"\" + filename + "";
                    isExistImage      = CheckIfImageExists(filename, imgFolder);
                    if (!(isExistImage))
                    {
                        ImageSettings imgStng = new ImageSettings(aspxCommonObj);
                        if (Convert.ToBoolean(imgStng.ResizeImagesProportionally) == true)
                        {
                            resizeSetings.Width = imgStng.ItemMediumThumbNailWidth;
                        }
                        else
                        {
                            resizeSetings.Width  = imgStng.ItemMediumThumbNailWidth;
                            resizeSetings.Height = imgStng.ItemMediumThumbNailWidth;
                        }
                        copyOriginalImageToRespectives(resizeSetings, sourceFolder, destinationFolder, aspxCommonObj, isWM);
                    }
                    break;
                }

                case ImageType.Small:
                {
                    string imgFolder = imageSourceloc + @"" + type + "";
                    destinationFolder = imgDestintionloc + @"" + type + @"\" + filename + "";
                    isExistImage      = CheckIfImageExists(filename, imgFolder);
                    if (!(isExistImage))
                    {
                        ImageSettings imgStng = new ImageSettings(aspxCommonObj);
                        if (Convert.ToBoolean(imgStng.ResizeImagesProportionally) == true)
                        {
                            resizeSetings.Width = imgStng.ItemSmallThumbNailHeight;
                        }
                        else
                        {
                            resizeSetings.Width  = imgStng.ItemSmallThumbNailHeight;
                            resizeSetings.Height = imgStng.ItemSmallThumbNailHeight;
                        }
                        copyOriginalImageToRespectives(resizeSetings, sourceFolder, destinationFolder, aspxCommonObj, isWM);
                    }
                    break;
                }
                }
            }
            catch
            {
            }
        }
        /// <summary>
        /// Copies image file to the destination.The destination need not have the file but the destination must add the original file name in its path
        /// </summary>
        /// <param name="rs">The resize setting</param>
        /// <param name="SourceFile">The original image file</param>
        /// <param name="DestinationFolder">The path of the destination folder including the filename same as original image file</param>
        public static void copyOriginalImageToRespectives(ResizeSettings rs, string SourceFile, string DestinationFolder,AspxCommonInfo aspxCommonObj,IsWaterMark isWaterMark)
        {
            
            // string combinedPath = Path.Combine(SourceFolder, filename);
          
                if (isWaterMark.ToString() == "True")
                {
                    //ResizeSettings settingObj = 
                    ApplyWaterMarkToImage(aspxCommonObj, rs,SourceFile, DestinationFolder);
                }
                else
                {
                    using (FileStream fileStream = new FileStream(SourceFile, FileMode.Open))
                    {
                        ImageJob i = new ImageJob(fileStream, DestinationFolder, new Instructions(rs));
                        i.CreateParentDirectory = false; //Auto-create the uploads directory.
                        i.Build();
                    }
                
            }
           

        }