meta info
- Title: LazZiya.ImageResize - Add Text Watermark
- Keywords: asp.net-core, image, resize, crop, scale, text watermark, animated, gif
- Description: Image resizing tool for .Net applications to resize images and add text/image watermark, Supports most common image types including animated gif.
- Author: Ziya Mollamahmut
- Date: 10-Feb-2021
- Image: https://github.com/LazZiya/Docs/raw/master/LazZiya.ImageResize/v4.0/images/lazziya-imageresize-logo.png
- Image-alt: LazZiya.ImageResize Logo
- Version: v4.0
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");
}
AddTextWatermark
can be overloaded with an additional optional parameter:TextWatermarkOptions
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");
}
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 obtained from Giphy