PowerShell: Base64 compression to clipboard

Just another Tech site

PowerShell: Base64 compression to clipboard

Using the Base64 to embed logos into a Windows form and then compressing the image to reduce the footprint of the size of the code.

Add-Type -AssemblyName System.IO.Compression
$imagePath = "Location to file\firefoxlogosmall.png"
$bytes = [System.IO.File]::ReadAllBytes($imagePath)

$ms = New-Object System.IO.MemoryStream
$gzip = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Compress)
$gzip.Write($bytes, 0, $bytes.Length)
$gzip.Close()

$base64 = [Convert]::ToBase64String($ms.ToArray())
Set-Clipboard -Value $base64  # Copy to clipboard for pasting into script