示例#1
0
        protected RequestedAction RenderLayersForLevel(ImageState s, Layer.LayerPlacement only)
        {
            string watermark;

            string[] parts = WatermarksToUse(s.settings, out watermark);
            Graphics g     = s.destGraphics;

            if (parts == null || g == null)
            {
                return(RequestedAction.None);
            }

            bool foundPart = false;

            foreach (string w in parts)
            {
                if (NamedWatermarks.ContainsKey(w))
                {
                    IEnumerable <Layer> layers = NamedWatermarks[w];
                    foreach (Layer l in layers)
                    {
                        if (l.DrawAs == only)
                        {
                            l.RenderTo(s);
                        }
                    }
                    foundPart = true;
                }
            }

            if (!foundPart && only == Layer.LayerPlacement.Overlay)
            {
                //Parse named watermark files
                ImageLayer layer = this.CreateLayerFromOtherImages(watermark);

                if (layer != null)
                {
                    layer.RenderTo(s);
                }
                else
                {
                    this.LegacyDrawWatermark(s);
                }
            }

            return(RequestedAction.None);
        }
示例#2
0
        protected Dictionary<string, IEnumerable<Layer>> ParseWatermarks(Node n, ref ImageLayer otherImageDefaults)
        {
            Dictionary<string, IEnumerable<Layer>> dict = new Dictionary<string, IEnumerable<Layer>>(StringComparer.OrdinalIgnoreCase);
            if (n == null || n.Children == null) return dict;
            foreach (Node c in n.Children) {
                //Verify the name is specified and is unique.
                string name = c.Attrs["name"];
                if (c.Name.Equals("image", StringComparison.OrdinalIgnoreCase)
                    || c.Name.Equals("text", StringComparison.OrdinalIgnoreCase)
                    || c.Name.Equals("group", StringComparison.OrdinalIgnoreCase)) {
                    if (string.IsNullOrEmpty(name) || dict.ContainsKey(name)) {
                        this.c.configurationSectionIssues.AcceptIssue(new Issue("WatermarkPlugin", "The name attribute for each watermark or watermark group must be specified, and must be unique.",
                        "XML: " + c.ToString(), IssueSeverity.ConfigurationError));
                        continue;
                    }
                }

                if (c.Name.Equals("otherimages", StringComparison.OrdinalIgnoreCase)) otherImageDefaults = new ImageLayer(c.Attrs, this.c);
                if (c.Name.Equals("image", StringComparison.OrdinalIgnoreCase)) dict.Add(name, new Layer[]{new ImageLayer(c.Attrs, this.c)});
                if (c.Name.Equals("text", StringComparison.OrdinalIgnoreCase)) dict.Add(name, new Layer[] {new TextLayer(c.Attrs) });
                if (c.Name.Equals("group", StringComparison.OrdinalIgnoreCase)) {

                    List<Layer> layers = new List<Layer>();
                    if (c.Children != null) {
                        foreach (Node layer in c.Children) {
                            if (layer.Name.Equals("image", StringComparison.OrdinalIgnoreCase)) layers.Add(new ImageLayer(layer.Attrs, this.c));
                            if (layer.Name.Equals("text", StringComparison.OrdinalIgnoreCase)) layers.Add(new TextLayer(layer.Attrs));
                        }
                    }
                    dict.Add(name, layers);
                }
            }
            return dict;
        }
        /// <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 
            {
            }
        }
示例#4
0
        protected Dictionary <string, IEnumerable <Layer> > ParseWatermarks(Node n, ref ResizeSettings defaultImageQuery, ref ImageLayer otherImageDefaults)
        {
            // Grab the defaultImageQuery value (if it exists) from the watermarks
            // node, so that we can apply them to any subsequent image watermarks.
            if (n != null && !string.IsNullOrEmpty(n.Attrs["defaultImageQuery"]))
            {
                defaultImageQuery = new ResizeSettings(n.Attrs["defaultImageQuery"]);
            }

            Dictionary <string, IEnumerable <Layer> > dict = new Dictionary <string, IEnumerable <Layer> >(StringComparer.OrdinalIgnoreCase);

            if (n == null || n.Children == null)
            {
                return(dict);
            }
            foreach (Node c in n.Children)
            {
                //Verify the name is specified and is unique.
                string name = c.Attrs["name"];
                if (c.Name.Equals("image", StringComparison.OrdinalIgnoreCase) ||
                    c.Name.Equals("text", StringComparison.OrdinalIgnoreCase) ||
                    c.Name.Equals("group", StringComparison.OrdinalIgnoreCase))
                {
                    if (string.IsNullOrEmpty(name) || dict.ContainsKey(name))
                    {
                        this.c.configurationSectionIssues.AcceptIssue(new Issue("WatermarkPlugin", "The name attribute for each watermark or watermark group must be specified, and must be unique.",
                                                                                "XML: " + c.ToString(), IssueSeverity.ConfigurationError));
                        continue;
                    }
                }


                if (c.Name.Equals("otherimages", StringComparison.OrdinalIgnoreCase))
                {
                    otherImageDefaults = new ImageLayer(c.Attrs, defaultImageQuery, this.c);
                }
                if (c.Name.Equals("image", StringComparison.OrdinalIgnoreCase))
                {
                    dict.Add(name, new Layer[] { new ImageLayer(c.Attrs, defaultImageQuery, this.c) });
                }
                if (c.Name.Equals("text", StringComparison.OrdinalIgnoreCase))
                {
                    dict.Add(name, new Layer[] { new TextLayer(c.Attrs) });
                }
                if (c.Name.Equals("group", StringComparison.OrdinalIgnoreCase))
                {
                    List <Layer> layers = new List <Layer>();
                    if (c.Children != null)
                    {
                        foreach (Node layer in c.Children)
                        {
                            if (layer.Name.Equals("image", StringComparison.OrdinalIgnoreCase))
                            {
                                layers.Add(new ImageLayer(layer.Attrs, defaultImageQuery, this.c));
                            }
                            if (layer.Name.Equals("text", StringComparison.OrdinalIgnoreCase))
                            {
                                layers.Add(new TextLayer(layer.Attrs));
                            }
                        }
                    }
                    dict.Add(name, layers);
                }
            }
            return(dict);
        }
示例#5
0
 public void CopyTo(ImageLayer other)
 {
     base.CopyTo(other);
     other.Path = Path;
     other.ImageQuery = new ResizeSettings(ImageQuery);
 }
示例#6
0
 public ImageLayer Copy()
 {
     ImageLayer l = new ImageLayer(this.c);
     this.CopyTo(l);
     return l;
 }
示例#7
0
 public void CopyTo(ImageLayer other)
 {
     base.CopyTo(other);
     other.Path       = Path;
     other.ImageQuery = new ResizeSettings(ImageQuery);
 }