-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-icon.swift
More file actions
79 lines (65 loc) · 2.83 KB
/
Copy pathgenerate-icon.swift
File metadata and controls
79 lines (65 loc) · 2.83 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env swift
// generate-icon.swift — Generate a mic icon for the app using SF Symbols
// Usage: swift generate-icon.swift <output-dir>
// Creates AppIcon.icns in the output directory.
import AppKit
import Foundation
let outputDir = CommandLine.arguments.count > 1
? CommandLine.arguments[1]
: FileManager.default.currentDirectoryPath
// Create a 1024x1024 mic icon
func createMicIcon(size: CGFloat) -> NSImage {
let image = NSImage(size: NSSize(width: size, height: size))
image.lockFocus()
// Background: rounded rectangle with gradient
let rect = NSRect(x: 0, y: 0, width: size, height: size)
let cornerRadius = size * 0.22 // macOS icon corner radius
let path = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius)
// Gradient background: warm orange to red
let gradient = NSGradient(colors: [
NSColor(red: 1.0, green: 0.45, blue: 0.2, alpha: 1.0), // warm orange
NSColor(red: 0.9, green: 0.2, blue: 0.3, alpha: 1.0), // red
])!
gradient.draw(in: path, angle: -45)
// Draw SF Symbol mic
if let sfImage = NSImage(systemSymbolName: "mic.fill", accessibilityDescription: nil) {
let config = NSImage.SymbolConfiguration(pointSize: size * 0.5, weight: .medium)
let configured = sfImage.withSymbolConfiguration(config)!
// Get the symbol's size for centering
let symbolSize = configured.size
let x = (size - symbolSize.width) / 2
let y = (size - symbolSize.height) / 2
// Draw white mic symbol
NSColor.white.set()
let symbolRect = NSRect(x: x, y: y, width: symbolSize.width, height: symbolSize.height)
configured.draw(in: symbolRect, from: .zero, operation: .sourceOver, fraction: 1.0)
}
image.unlockFocus()
return image
}
// Generate icon at various sizes
let sizes: [(Int, String)] = [
(16, "icon_16x16"),
(32, "icon_16x16@2x"),
(32, "icon_32x32"),
(64, "icon_32x32@2x"),
(128, "icon_128x128"),
(256, "icon_128x128@2x"),
(256, "icon_256x256"),
(512, "icon_256x256@2x"),
(512, "icon_512x512"),
(1024, "icon_512x512@2x"),
]
let iconsetDir = (outputDir as NSString).appendingPathComponent("AppIcon.iconset")
try? FileManager.default.removeItem(atPath: iconsetDir)
try! FileManager.default.createDirectory(atPath: iconsetDir, withIntermediateDirectories: true)
for (size, name) in sizes {
let image = createMicIcon(size: CGFloat(size))
let tiffData = image.tiffRepresentation!
let bitmap = NSBitmapImageRep(data: tiffData)!
let pngData = bitmap.representation(using: .png, properties: [:])!
let filePath = (iconsetDir as NSString).appendingPathComponent("\(name).png")
try! pngData.write(to: URL(fileURLWithPath: filePath))
}
print("Iconset created at \(iconsetDir)")
print("Run: iconutil --convert icns \(iconsetDir)")