views:

85

answers:

1

Hi, I just wondered if it would be possible to create a small, simple jpg, png, gif with a given Text in powershell:

e.g: a small square, 250px × 61px, yellow background and black text on it: "Test"

Can I do this with "System.Drawing.Image"?

Thanks

+2  A: 

Sure, if you're on PowerShell 2.0 try this:

Add-Type -AssemblyName System.Drawing

$filename = "$home\foo.png" 
$bmp = new-object System.Drawing.Bitmap 250,61 
$font = new-object System.Drawing.Font Consolas,24 
$brushBg = [System.Drawing.Brushes]::Yellow 
$brushFg = [System.Drawing.Brushes]::Black 
$graphics = [System.Drawing.Graphics]::FromImage($bmp) 
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height) 
$graphics.DrawString('Hello World',$font,$brushFg,10,10) 
$graphics.Dispose() 
$bmp.Save($filename) 

Invoke-Item $filename  
Keith Hill
Works perfectly! Thanks
icnivad