Skip to content

Instantly share code, notes, and snippets.

@mcenirm
Created January 5, 2021 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcenirm/e0cbecf6eaf0bec810e6a05c88f2dfa9 to your computer and use it in GitHub Desktop.
Save mcenirm/e0cbecf6eaf0bec810e6a05c88f2dfa9 to your computer and use it in GitHub Desktop.
Make an image using PowerShell and System.Drawing
#Requires -Version 2
# https://stackoverflow.com/a/2068019
Add-Type -AssemblyName System.Drawing
$filename = "$psscriptroot\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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment