Last active
February 16, 2023 09:31
-
-
Save tdewin/8153846129a2c423441f0618ee4e7064 to your computer and use it in GitHub Desktop.
Convert a text ($colors) full of hex colors to a GIMP Palette/gpl file, for Inkscape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $colors = @" | |
| #333333 | |
| #222222 | |
| #FFFFFF #444433 | |
| "@ | |
| $theme = "mytheme" | |
| $lns = @("GIMP Palette","Name: $theme","#") | |
| $cregx = [Regex]::new("#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})[^a-fA-F0-9]") | |
| function cc { param($hex) [System.Convert]::ToInt16($hex.ToUpper(), 16);} | |
| foreach ($color in $cregx.Matches($colors)) { | |
| $gr = ($color.Groups[1].Value,$color.Groups[2].Value,$color.Groups[3].Value) | |
| $lns += ("{0,3} {1,3} {2,3} #{3}" -f (cc $gr[0]),(cc $gr[1]),(cc $gr[2]), ($gr -join "")) | |
| } | |
| # C:\Program Files\Inkscape\share\inkscape\palettes but might not be direct writeable by ps1 | |
| $out = Join-Path -Path "C:\d\" -ChildPath ("$theme.gpl") | |
| $textout = $lns -join "`n" | |
| $textout | set-content -Path $out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment