-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_colors.ps1
More file actions
50 lines (44 loc) · 1.76 KB
/
extract_colors.ps1
File metadata and controls
50 lines (44 loc) · 1.76 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Add-Type -AssemblyName System.Drawing
$files = @("public/assets/logo-mark-1.png", "public/assets/logo-mark-2.png", "public/assets/logo-mark-3.png")
foreach ($file in $files) {
if (Test-Path $file) {
Write-Host "Analyzing $file..."
try {
$img = [System.Drawing.Bitmap]::FromFile((Get-Item $file).FullName)
$colors = @{}
# Subsample pixels for speed (step 10)
for ($x = 0; $x -lt $img.Width; $x += 10) {
for ($y = 0; $y -lt $img.Height; $y += 10) {
$pixel = $img.GetPixel($x, $y)
# Skip transparent
if ($pixel.A -gt 240) {
# Skip near-white (R+G+B > 720)
$brightness = $pixel.R + $pixel.G + $pixel.B
if ($brightness -lt 720) {
$hex = "#{0:X2}{1:X2}{2:X2}" -f $pixel.R, $pixel.G, $pixel.B
if ($colors.ContainsKey($hex)) {
$colors[$hex]++
}
else {
$colors[$hex] = 1
}
}
}
}
}
# Sort and pick top 5
$topColors = $colors.GetEnumerator() | Sort-Object Value -Descending | Select-Object -First 5
Write-Host "Top Colors for $file :"
foreach ($c in $topColors) {
Write-Host " $($c.Key): $($c.Value)"
}
$img.Dispose()
}
catch {
Write-Host "Error processing $file : $_"
}
}
else {
Write-Host "File not found: $file"
}
}