コード例 #1
0
ファイル: TestAll.cs プロジェクト: eakova/resizer
        public Config GetConfig()
        {
            Config c = new Config();
            //c.Pipeline.s
            WatermarkPlugin w = new ImageResizer.Plugins.Watermark.WatermarkPlugin();
            w.align = System.Drawing.ContentAlignment.BottomLeft;
            w.hideIfTooSmall = false;
            w.keepAspectRatio = true;
            w.valuesPercentages = true;
            w.watermarkDir = "~/"; //Where the watermark plugin looks for the image specifed in the querystring ?watermark=file.png
            w.bottomRightPadding = new System.Drawing.SizeF(0, 0);
            w.topLeftPadding = new System.Drawing.SizeF(0, 0);
            w.watermarkSize = new System.Drawing.SizeF(1, 1); //The desired size of the watermark, maximum dimensions (aspect ratio maintained if keepAspectRatio = true)
            //Install the plugin
            w.Install(c);

            new Gradient().Install(c);
            new PrettyGifs().Install(c);
            new AnimatedGifs().Install(c);
            new AdvancedFilters().Install(c);
            RemoteReaderPlugin rrp = new RemoteReaderPlugin(); rrp.Install(c);
            rrp.AllowRemoteRequest += delegate(object sender, RemoteRequestEventArgs args) {
                args.DenyRequest = false;
            }; //Doesn't support non-ASP.NET usage yet.

            new SeamCarvingPlugin().Install(c);
            new SimpleFilters().Install(c);
            new DropShadow().Install(c);
            new WhitespaceTrimmerPlugin().Install(c);
            //s3reader
            //sqlreader

            return c;
        }
コード例 #2
0
        public static Config GetConfig()
        {
            Config c = new Config();
            //c.Pipeline.s
            WatermarkPlugin w = new ImageResizer.Plugins.Watermark.WatermarkPlugin();

            w.align              = System.Drawing.ContentAlignment.BottomLeft;
            w.hideIfTooSmall     = false;
            w.keepAspectRatio    = true;
            w.valuesPercentages  = true;
            w.watermarkDir       = "~/"; //Where the watermark plugin looks for the image specified in the querystring ?watermark=file.png
            w.bottomRightPadding = new System.Drawing.SizeF(0, 0);
            w.topLeftPadding     = new System.Drawing.SizeF(0, 0);
            w.watermarkSize      = new System.Drawing.SizeF(1, 1); //The desired size of the watermark, maximum dimensions (aspect ratio maintained if keepAspectRatio = true)
            //Install the plugin
            w.Install(c);

            new Gradient().Install(c);
            new PrettyGifs().Install(c);
            new AnimatedGifs().Install(c);
            new AdvancedFilters().Install(c);
            RemoteReaderPlugin rrp = new RemoteReaderPlugin(); rrp.Install(c);

            rrp.AllowRemoteRequest += delegate(object sender, RemoteRequestEventArgs args) {
                args.DenyRequest = false;
            }; //Doesn't support non-ASP.NET usage yet.

            new SeamCarvingPlugin().Install(c);
            new SimpleFilters().Install(c);
            new DropShadow().Install(c);
            new WhitespaceTrimmerPlugin().Install(c);
            new VirtualFolder("/images", "..\\..\\..\\Samples\\Images", false).Install(c);

            new ImageResizer.Plugins.SourceMemCache.SourceMemCachePlugin().Install(c);

            //s3reader
            //sqlreader

            return(c);
        }
コード例 #3
0
        /// <summary>
        /// Applyes watermark to the image based on the isWaterMark property of that image
        /// </summary>
        /// <param name="aspxCommonObj">Common Object aspx</param>
        /// <param name="rs">Resize settings</param>
        /// <param name="SourceFile">The full source path of image</param>
        /// <param name="DestinationFolder">The full destination path of the image</param>
        public static void ApplyWaterMarkToImage(AspxCommonInfo aspxCommonObj, ResizeSettings rs, string SourceFile,string DestinationFolder)
        {
             
            StoreSettingConfig ssc = new StoreSettingConfig();
            string waterMarkText = ssc.GetStoreSettingsByKey(StoreSetting.WaterMarkText, aspxCommonObj.StoreID,
                                                             aspxCommonObj.PortalID, aspxCommonObj.CultureName);


            try
            {

                if (!string.IsNullOrEmpty(waterMarkText))
                {
                    string waterMarkposition = ssc.GetStoreSettingsByKey(StoreSetting.WaterMarkTextPosition,
                                                                         aspxCommonObj.StoreID, aspxCommonObj.PortalID,
                                                                         aspxCommonObj.CultureName);
                    double waterMarkRotAngle =
                        double.Parse(ssc.GetStoreSettingsByKey(StoreSetting.WaterMarkTextRotation, aspxCommonObj.StoreID,
                                                               aspxCommonObj.PortalID, aspxCommonObj.CultureName));

                   bool showWaterMarkImage = bool.Parse(ssc.GetStoreSettingsByKey(StoreSetting.ShowWaterMarkImage,
                                                                                   aspxCommonObj.StoreID,
                                                                                   aspxCommonObj.PortalID,
                                                                                   aspxCommonObj.CultureName));
                  

                    //You can have multiple configurations. Config.Current contains web.config settings, but you can use new Config(); to get a clean slate.
                    Config c = Config.Current;

                    //Get a reference to the instance 
                    WatermarkPlugin wp = c.Plugins.Get<WatermarkPlugin>();
                    if (wp == null)
                    { //Install it if it's missing
                        wp = new WatermarkPlugin();
                        wp.Install(c);
                    }
                    //Re-query in case another thread beat us  to installation.
                        wp = c.Plugins.Get<WatermarkPlugin>();
                    
                     //Adding single text layer multiple layer can be added
                     TextLayer t = new TextLayer();
                     t.Text = waterMarkText;
                     t.Fill = true; //Fill the image with the text
                     t.TextColor = System.Drawing.Color.White;
                     t.Angle = waterMarkRotAngle;
                     TextPosition posType = (TextPosition)Enum.Parse(typeof(TextPosition), waterMarkposition);
                     if (!string.IsNullOrEmpty(posType.ToString()))
                     {

                         switch (posType)
                         {
                             case TextPosition.BOTTOM_CENTER:
                                 t.Left = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Right = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Bottom = new DistanceUnit(5, DistanceUnit.Units.Percentage);

                                 break;
                             case TextPosition.MID_CENTER:
                                 t.Left = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Right = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Bottom = new DistanceUnit(50, DistanceUnit.Units.Percentage);

                                 break;
                             case TextPosition.TOP_CENTER:
                                 t.Left = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Right = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Top = new DistanceUnit(5, DistanceUnit.Units.Percentage);

                                 break;
                             case TextPosition.BOTTOM_LEFT:
                                 t.Left = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Bottom = new DistanceUnit(5, DistanceUnit.Units.Percentage);

                                 break;
                             case TextPosition.MID_LEFT:
                                 t.Left = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Top = new DistanceUnit(50, DistanceUnit.Units.Percentage);

                                 break;
                             case TextPosition.TOP_LEFT:
                                 t.Left = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Top = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                 break;
                             default:
                                 t.Left = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Right = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                                 t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                                 t.Bottom = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                 break;
                         }
                     }
                     else
                     {
                         t.Left = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                         t.Right = new DistanceUnit(30, DistanceUnit.Units.Percentage);
                         t.Width = new DistanceUnit(50, DistanceUnit.Units.Percentage);
                         t.Bottom = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                     }
                   
                    wp.NamedWatermarks["text"] = new Layer[] { t };
                    ResizeSettings rsWM;
                    if (showWaterMarkImage)
                    {
                        string waterMarkImageposition = ssc.GetStoreSettingsByKey(StoreSetting.WaterMarkImagePosition,
                                                                             aspxCommonObj.StoreID,
                                                                             aspxCommonObj.PortalID,
                                                                             aspxCommonObj.CultureName);
                        double waterMarkImageRotAngle =
                            double.Parse(ssc.GetStoreSettingsByKey(StoreSetting.WaterMarkImageRotation,
                                                                   aspxCommonObj.StoreID, aspxCommonObj.PortalID,
                                                                   aspxCommonObj.CultureName));

                        string imagePath =@"Modules\AspxCommerce\AspxStoreSettingsManagement\uploads\noitem.png";
                        ImageLayer i = new ImageLayer(c); //ImageLayer needs a Config instance so it knows where to locate images
                        i.Path = "~/" + imagePath;
                        i.DrawAs = ImageLayer.LayerPlacement.Overlay;
                        i.Width = new DistanceUnit(20, DistanceUnit.Units.Percentage);
                        i.Height = new DistanceUnit(20, DistanceUnit.Units.Percentage);
                        i.ImageQuery.Rotate = waterMarkImageRotAngle;
                        ImagePosition imgPosType = (ImagePosition)Enum.Parse(typeof(ImagePosition), waterMarkImageposition);
                        if (!string.IsNullOrEmpty(imgPosType.ToString()))
                        {
                            switch (imgPosType)
                            {
                                case ImagePosition.CENTER:
                                    break;

                                case ImagePosition.TOP_RIGHT:
                                    i.Top = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    i.Right = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    break;

                                case ImagePosition.TOP_LEFT:
                                    i.Top = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    i.Left = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    break;

                                case ImagePosition.BOTTOM_RIGHT:
                                    i.Bottom = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    i.Right = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    break;

                                case ImagePosition.BOTTOM_LEFT:
                                    i.Bottom = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    i.Left = new DistanceUnit(5, DistanceUnit.Units.Percentage);
                                    break;
                                default:
                                    i.Width = new DistanceUnit(20, DistanceUnit.Units.Percentage);
                                    i.Height = new DistanceUnit(20, DistanceUnit.Units.Percentage);
                                    break;
                            }
                        }
                        
                       wp.NamedWatermarks["img"] = new Layer[] { i };
                       rsWM = new ResizeSettings("watermark=text,img;");
                    }
                    else
                    {
                       rsWM = new ResizeSettings("watermark=text");
                    }
                    rsWM.Format = rs.Format;
                    rsWM.Mode = rs.Mode;
                    rsWM.Scale = rs.Scale;
                    rsWM.Quality = rs.Quality;
                    rsWM.Width = rs.Width;
                    rsWM.Height = rs.Height;
                    wp.keepAspectRatio = true; //Maintains the aspect ratio of the watermark itself.
                    //Build the Image
                    c.CurrentImageBuilder.Build(SourceFile, DestinationFolder, rsWM);
                }
            }
            catch 
            {
            }
        }