# Generate extension icons (16 / 32 / 48 / 128). Zero dependency: System.Drawing only. # # Usage (PowerShell 5.1): # powershell -ExecutionPolicy Bypass -File tools\make-icons.ps1 # # IMPORTANT - keep this file pure ASCII. # PowerShell 5.1 on a zh-CN machine reads .ps1 files WITHOUT a BOM as GBK, so any UTF-8 # Chinese in here becomes mojibake; and mojibake inside a format string such as # ("done: {0}" -f $x) can even break parsing: "Input string was not in a correct format". # # Artwork: rounded gradient tile (deep blue -> teal) + white barcode bars. Add-Type -AssemblyName System.Drawing $root = Split-Path -Parent $PSScriptRoot # extension/ $outDir = Join-Path $root 'icons' New-Item -ItemType Directory -Force -Path $outDir | Out-Null function New-Icon([int]$size) { $bmp = New-Object System.Drawing.Bitmap($size, $size, [System.Drawing.Imaging.PixelFormat]::Format32bppArgb) $g = [System.Drawing.Graphics]::FromImage($bmp) $g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias $g.Clear([System.Drawing.Color]::Transparent) # ---- rounded rectangle background ---- $r = [Math]::Max(2, [int]($size * 0.22)) $d = $r * 2 $rect = New-Object System.Drawing.Rectangle(0, 0, $size, $size) $path = New-Object System.Drawing.Drawing2D.GraphicsPath $path.AddArc($rect.X, $rect.Y, $d, $d, 180, 90) $path.AddArc($rect.Right - $d, $rect.Y, $d, $d, 270, 90) $path.AddArc($rect.Right - $d, $rect.Bottom - $d, $d, $d, 0, 90) $path.AddArc($rect.X, $rect.Bottom - $d, $d, $d, 90, 90) $path.CloseAllFigures() $c1 = [System.Drawing.Color]::FromArgb(255, 12, 74, 110) $c2 = [System.Drawing.Color]::FromArgb(255, 14, 165, 164) $brush = [System.Drawing.Drawing2D.LinearGradientBrush]::new($rect, $c1, $c2, [single]45) $g.FillPath($brush, $path) # ---- white barcode bars, alternating heights ---- $white = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb(255, 255, 255, 255)) $barW = [Math]::Max(1, [int]($size * 0.075)) $gap = [Math]::Max(1, [int]($size * 0.055)) $x = [int]($size * 0.20) $top = [int]($size * 0.28) $bot = [int]($size * 0.72) $limit = $size * 0.82 $ratios = @(0.55, 1.0, 0.72, 1.0, 0.6, 0.88, 1.0, 0.66) foreach ($ratio in $ratios) { if ($x + $barW -gt $limit) { break } $h = [int](($bot - $top) * $ratio) $g.FillRectangle($white, $x, ($bot - $h), $barW, $h) $x += $barW + $gap } $g.Dispose() $brush.Dispose() $white.Dispose() $path.Dispose() $file = Join-Path $outDir ("icon{0}.png" -f $size) $bmp.Save($file, [System.Drawing.Imaging.ImageFormat]::Png) $bmp.Dispose() Write-Host (" {0,-16} {1}x{1}" -f (Split-Path -Leaf $file), $size) } Write-Host 'Building icons ->' foreach ($s in 16, 32, 48, 128) { New-Icon $s } Write-Host ('Done. Output: {0}' -f $outDir)