Sunday, April 06, 2008 4:10 PM
by
loufranco
My notes for Extending Powershell to do Image Processing, Part I
Ok, you're going to want to install Powershell before reading the rest of this. Once, you've done that, try typing these commands at the prompt (type in what appears after the >, the text in italics is just commentary):
Here's the hello world program
> "hello world"
Remember, the result of your expression is just printed by the shell. "hello world" is a .NET System.String
Here's some other primitives and simple expressions:
> 3
> 3+4
> 1GB
> "hello " + "world"
> "hello world".substring(6)
> 1..10
Remember that Powershell's directory primitives operate on a provider interface. You can call dir and cd on anything that implements it (like the registry)
> cd HKLM:\
> dir
> cd SOFTWARE\Microsoft\Windows
> dir
> c:
> dir
There is extensive built-in help:
> get-help get-process
> get-command *process*
> "hello" | get-member
> get-history
> get-command *history*
You can call .NET assemblies (variables start with $)
> $feed = [xml](new-object System.Net.WebClient).DownloadString(
"http://www.atalasoft.com/cs/blogs/loufranco/rss.aspx"
)
> $feed.rss.channel.item | select title
> $feed.rss.channel.item | ? { $_.title -match "ower" }
And you can call any third-party assemblies (like DotImage). Once you have installed DotImage, copy Atalasoft.Shared.dll, Atalasoft.DotImage.dll and Atalasoft.DotImage.Lib.dll to C:\WINDOWS\system32\windowspowershell\v1.0 -- this is one of the places Powershell looks for assemblies. You load them like this:
> [System.Reflection.Assembly]::Load("atalasoft.dotimage")
> [System.Reflection.Assembly]::Load("atalasoft.dotimage.lib")
> [System.Reflection.Assembly]::Load("atalasoft.shared")
In all of the next examples, you'll want to give full paths to filenames -- Powershell has an odd notion of the current directory which is confusing to explain right now.
Here's how you load an image
> $img = new-object Atalasoft.Imaging.AtalaImage("fullpath to image")
And now run the oilpaint command
> $cmd = new-object Atalasoft.Imaging.ImageProcessing.Effects.OilPaintCommand
> $cmd.BrushWidth = 15
> $img2 = $cmd.Apply($img).Image
And save it (any undefined variable is null, so don't define $null)
> $img2.Save("full path to image", (new-object Atalasoft.Imaging.Codec.JpegEncoder(85)), $null)
That turns this
into this
Tomorrow I'll post the code that makes it easier to do this (using Cmdlets)
Update: Here is Image Processing with Powershell, Part II