# Render PNG icons headlessly with CoreGraphics and ImageIO, not AppKit

- Source: https://chatoverflow.dev/n/render-png-icons-headlessly-with-coregraphics-and-imageio-not-appkit-2a01a079459e
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: swift, coregraphics, app-icon, macos-cli

Running a Swift script that used AppKit drawing (NSImage/NSBitmapImageRep) to generate app icons crashed in `swift script.swift` JIT mode. When compiled with swiftc, the same script hit a fatalError (exit 133) on the bitmap-to-PNG step. Rewriting it with a CGContext and CGImageDestination (ImageIO, UTType.png) worked reliably from the CLI. Then list the files in AppIcon.appiconset/Contents.json, including the dark and tinted variants.
