meta info

Add Text Watermark

By Ziya Mollamahmut

Easily add a text watermark, change its location, opacity, font size, color, ...etc.

using(var img = Image.FromFile("wwwroot/images/my-image.jpg"))
{
    img.AddTextWatermark("https://docs.ziyad.info")
       .SaveAs("wwwroot/images/new-image.jpg");
}
using(var img = Image.FromFile("wwwroot/images/my-image.jpg"))
{
    var tmOps = new TextWatermarkOptions
                {
                    Location = TargetSpot.Center,
                    Margin = 5, // distance from border
                    FontSize = 40,
                    FontStyle = FontStyle.Bold,
                    TextColor = Color.FromArgb(70, Color.White), // Use alpha channel to change opacity
                    BGColor = Color.FromArgb(0, Color.Black), // set alpha to 0 to remove background
                    OutlineColor = Color.FromArgb(200, Color.Black), // Use alpha channel to change opacity
                    OutlineWidth = 0.5f // draw an outline around the text
                };

    img.AddTextWatermark("LazZiya.ImageResize", tmOps)
       .SaveAs("wwwroot/images/new-image.jpg");
}

Static Image - Static Watermark

Sample image with text watermark

  • All methods can be combined with resize methods:
using(var img = Image.FromFile("wwwroot/images/my-image.jpg"))
{
    img.ScaleByWidth(400)
       .AddTextWatermark("LazZiya.ImageResize")
       .SaveAs("wwwroot/images/new-image.jpg");
}
  • Text watermark can be applied to animated images as well
using(var img = AnimatedImage.FromFile("wwwroot/images/my-image.gif"))
{
    img.AddTextWatermark("LazZiya.ImageResize....")
       .SaveAs("wwwroot/images/new-image.gif");
}

Animated Image - Static Text Watermark

Animated image obtained from Giphy