/// <summary> /// Adds text watermark to a WebImage. /// </summary> /// <param name="text">Text to use as a watermark.</param> /// <param name="fontColor">Watermark color. Can be specified as a string (e.g. "White") or as a hex value (e.g. "#00FF00").</param> /// <param name="fontSize">Font size in points.</param> /// <param name="fontStyle">Font style: bold, italics, etc.</param> /// <param name="fontFamily">Font family name: e.g. Microsoft Sans Serif</param> /// <param name="horizontalAlign">Horizontal alignment for watermark text. Can be "right", "left", or "center".</param> /// <param name="verticalAlign">Vertical alignment for watermark text. Can be "top", "bottom", or "middle".</param> /// <param name="opacity">Watermark text opacity. Should be between 0 and 100.</param> /// <param name="padding">Size of padding around watermark text in pixels.</param> /// <returns>Modified WebImage instance with added watermark.</returns> public WebImage AddTextWatermark( string text, string fontColor = "Black", int fontSize = 12, string fontStyle = "Regular", string fontFamily = "Microsoft Sans Serif", string horizontalAlign = "Right", string verticalAlign = "Bottom", int opacity = 100, int padding = 5) { if (String.IsNullOrEmpty(text)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "text"); } Color color; if (!ConversionUtil.TryFromStringToColor(fontColor, out color)) { throw new ArgumentException(HelpersResources.WebImage_IncorrectColorName); } if ((opacity < 0) || (opacity > 100)) { throw new ArgumentOutOfRangeException("opacity", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_Between, 0, 100)); } int alpha = 255 * opacity / 100; color = Color.FromArgb(alpha, color); if (fontSize <= 0) { throw new ArgumentOutOfRangeException( "fontSize", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThan, 0)); } FontStyle fontStyleEnum; if (!ConversionUtil.TryFromStringToEnum(fontStyle, out fontStyleEnum)) { throw new ArgumentException(HelpersResources.WebImage_IncorrectFontStyle); } FontFamily fontFamilyClass; if (!ConversionUtil.TryFromStringToFontFamily(fontFamily, out fontFamilyClass)) { throw new ArgumentException(HelpersResources.WebImage_IncorrectFontFamily); } HorizontalAlign horizontalAlignEnum = ParseHorizontalAlign(horizontalAlign); VerticalAlign verticalAlignEnum = ParseVerticalAlign(verticalAlign); if (padding < 0) { throw new ArgumentOutOfRangeException( "padding", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0)); } WatermarkTextTransformation transformation = new WatermarkTextTransformation(text, color, fontSize, fontStyleEnum, fontFamilyClass, horizontalAlignEnum, verticalAlignEnum, padding); _transformations.Add(transformation); return(this); }
/// <summary> /// Adds text watermark to a WebImage. /// </summary> /// <param name="text">Text to use as a watermark.</param> /// <param name="fontColor">Watermark color. Can be specified as a string (e.g. "White") or as a hex value (e.g. "#00FF00").</param> /// <param name="fontSize">Font size in points.</param> /// <param name="fontStyle">Font style: bold, italics, etc.</param> /// <param name="fontFamily">Font family name: e.g. Microsoft Sans Serif</param> /// <param name="horizontalAlign">Horizontal alignment for watermark text. Can be "right", "left", or "center".</param> /// <param name="verticalAlign">Vertical alignment for watermark text. Can be "top", "bottom", or "middle".</param> /// <param name="opacity">Watermark text opacity. Should be between 0 and 100.</param> /// <param name="padding">Size of padding around watermark text in pixels.</param> /// <returns>Modified WebImage instance with added watermark.</returns> public WebImage AddTextWatermark( string text, string fontColor = "Black", int fontSize = 12, string fontStyle = "Regular", string fontFamily = "Microsoft Sans Serif", string horizontalAlign = "Right", string verticalAlign = "Bottom", int opacity = 100, int padding = 5) { if (string.IsNullOrEmpty(text)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "text"); } Color color; if (!ConversionUtil.TryFromStringToColor(fontColor, out color)) { throw new ArgumentException(HelpersResources.WebImage_IncorrectColorName); } if ((opacity < 0) || (opacity > 100)) { throw new ArgumentOutOfRangeException("opacity", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_Between, 0, 100)); } int alpha = 255 * opacity / 100; color = Color.FromArgb(alpha, color); if (fontSize <= 0) { throw new ArgumentOutOfRangeException( "fontSize", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThan, 0)); } FontStyle fontStyleEnum; if (!ConversionUtil.TryFromStringToEnum(fontStyle, out fontStyleEnum)) { throw new ArgumentException(HelpersResources.WebImage_IncorrectFontStyle); } FontFamily fontFamilyClass; if (!ConversionUtil.TryFromStringToFontFamily(fontFamily, out fontFamilyClass)) { throw new ArgumentException(HelpersResources.WebImage_IncorrectFontFamily); } HorizontalAlign horizontalAlignEnum = ParseHorizontalAlign(horizontalAlign); VerticalAlign verticalAlignEnum = ParseVerticalAlign(verticalAlign); if (padding < 0) { throw new ArgumentOutOfRangeException( "padding", String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0)); } WatermarkTextTransformation transformation = new WatermarkTextTransformation(text, color, fontSize, fontStyleEnum, fontFamilyClass, horizontalAlignEnum, verticalAlignEnum, padding); _transformations.Add(transformation); return this; }