Draw text watermark on thumbnail image
Pipeline Resize Thumbnail Text
This sample shows how to create a thumbnail image and draw a semi-transparent text watermark on top of it using the GraphicsMill transforms and advanced drawing APIs. It demonstrates how to resize the source image with the Resize transform, register a custom font, and render text with Drawer and PlainText. You can read more information about drawing in the documentation.
Сode Snippet
// Read the source image and prepare pipeline elements.
using (var reader = ImageReader.Create("Venice.jpg"))
using (var resize = new Resize(500, 500, ResizeInterpolationMode.Anisotropic9, ResizeMode.Fit))
using (var drawer = new Drawer())
using (var writer = new JpegWriter("TextWatermark.jpg"))
using (var fr = new CustomFontRegistry())
{
// Add font to the custom font registry and get its PostScript name.
var psName = fr.Add("Jost-Regular.ttf");
// Configure the Drawer to render the watermark text.
drawer.Draw += (sender, e) =>
{
// Set the custom font registry to the current graphics context.
e.Graphics.FontRegistry = fr;
// Create the font to be used for the watermark text.
var font = e.Graphics.CreateFont(psName, 50);
// Create the text object with semi-transparent white brush.
var text = new PlainText("WATERMARK TEXT", font)
{
Brush = new SolidBrush(RgbColor.White.ScaleAlpha(0.7f)),
Alignment = TextAlignment.Left,
};
// Place the text with a small margin from the left/bottom edges.
var margin = 10;
text.Position = new System.Drawing.PointF(margin, e.Height - margin);
// Draw the watermark text onto the image.
e.Graphics.DrawText(text);
};
// Run the pipeline.
Pipeline.Run(reader + resize + drawer + writer);
}
Input
Venice.jpg
Output
TextWatermark.jpg
For AI-assisted development: Download Graphics Mill Code Samples XML Catalog