Watermark images using PowerShell

by ravikanthchaganti on January 12, 2010
236 Views

We have been to a jungle resort over the weekend and took some good quality pictures. I wanted to watermark a few of them and then post it on a photo sharing site. Being a scripting fanatic and PowerShell lover, I wanted to see if I can achieve this using a PowerShell script. And, here is the result

Before watermarking

Before watermarking

Before watermarking

After watermarking

I used System.Drawing namespace to achieve this. You can download this script here

Watermark-Image (Downloaded 117 times)

After you dot-source the downloaded script, you can start watermarking images by running the following command

Watermark-Image -Source “C:\Images” -Destination “C:\WaterMarkedImages” -text “All rights reserved”

As you see in the above sample pictures, watermark text will be black color. You can modify the same by changing the following line in the script

$color = [System.Drawing.Color]::FromArgb(153, 0, 0,0)

The position of watermark will be the top-left corner. You can change that by specifying the pixel positions in the following line

$gImg.DrawString($text,$font,$myBrush,0,100)

Also, I am not taking care of output image format. It will always be JPEG. We can add that support as well by looking at the source extension. I will do that in a future release. We can extend this script to take out all above assumptions and capture everything from user input. This script is just a demonstration of what we can do using System.Drwaing namespace in PowerShell.

BTW, that is my son Kaustubh in the photograph. :)

Related Posts

{ 2 comments… read them below or add one }

John Smith May 19, 2010 at 8:31 pm

Excellent, just what I needed, I adapted it for the text to be centered and I had it read from a database, the result was instant greatness. Thanks.

ravikanthchaganti May 27, 2010 at 11:20 am

Glad it helped..!

{ 1 trackback }

Leave a Comment

Previous post:

Next post: