-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_ico.ps1
More file actions
29 lines (28 loc) · 899 Bytes
/
make_ico.ps1
File metadata and controls
29 lines (28 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Add-Type -AssemblyName System.Drawing
$pngPath = "logo.png"
$icoPath = "logo.ico"
$src = [System.Drawing.Image]::FromFile($pngPath)
$size = 256
$bmp = new-object System.Drawing.Bitmap($size, $size)
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$g.DrawImage($src, 0, 0, $size, $size)
$ms = new-object System.IO.MemoryStream
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
$pngBytes = $ms.ToArray()
$fs = new-object System.IO.FileStream($icoPath, [System.IO.FileMode]::Create)
$bw = new-object System.IO.BinaryWriter($fs)
$bw.Write([int16]0)
$bw.Write([int16]1)
$bw.Write([int16]1)
$bw.Write([byte]0)
$bw.Write([byte]0)
$bw.Write([byte]0)
$bw.Write([byte]0)
$bw.Write([int16]1)
$bw.Write([int16]32)
$bw.Write([int32]$pngBytes.Length)
$bw.Write([int32]22)
$bw.Write($pngBytes)
$bw.Close()
$fs.Close()