Making ICNS files
TIL: how to construct an ICNS file from a bunch of PNGs on MacOS.
MacOS uses an “ICNS” file to store icons in a variety of sizes and resolutions. Wikipedia’s description of th Apple Icon Image format says “asset catalogs” are preferred these days, so maybe there’ll be a TIL post about that some day. For the moment, I need an ICNS file (for the drive icons associated with a DMG file, in case you’re wondering).
Construct images in the resolutions you need. I started with some blank icons that were 16, 32, 256, 512, and 1024In fact, the ICNS file is apparently supposed to have 128 pixel versions as well, but I just let ImageMagick scale the 256 pixel version. Had I planned ahead, I could probably have just made one version at 1024 pixels and let ImageMagick scale them all. I didn’t plan ahead. pixels square.
Make an “.iconset” directory, I created DriveIcons.iconset
.
Use ImageMagick’s convert
(or any tool you like, I suppose) to make
the files. For the drive icons, I need 16x16, 16x16@2x (that’s 32x32),
32x32, 32x32@2x, 128x128, 128x128@2x, 256x256, 256x256@2x, 512x512,
and 512x512@2x sizes. Your application might need different ones,
but the technique is the same.
convert -geometry 16x16 Disk_16x16.png DriveIcons.iconset/icon_16x16.png
convert -geometry 32x32 Disk_32x32.png DriveIcons.iconset/icon_16x16@2x.png
convert -geometry 32x32 Disk_32x32.png DriveIcons.iconset/icon_32x32.png
convert -geometry 64x64 Disk_256x256.png DriveIcons.iconset/icon_32x32@2x.png
convert -geometry 128x128 Disk_256x256.png DriveIcons.iconset/icon_128x128.png
convert -geometry 256x256 Disk_256x256.png DriveIcons.iconset/icon_128x128@2x.png
convert -geometry 256x256 Disk_256x256.png DriveIcons.iconset/icon_256x256.png
convert -geometry 512x512 Disk_512x512.png DriveIcons.iconset/icon_256x256@2x.png
convert -geometry 512x512 Disk_512x512.png DriveIcons.iconset/icon_512x512.png
convert -geometry 1024x1024 Disk_1024x1024.png DriveIcons.iconset/icon_512x512@2x.png
It’s obviously kind of pointless to scale images to their current size, but there was less thinking involved this way and I’m going to script it all anyhow.
Next, use iconutil
to make the actual ICNS file:
iconutil -c icns DriveIcons.iconset
Of particular importance, the files in the icon set directory have to be named icon_…
.
I tried naming them Disk_…
the first time and got an error.
After you’ve created the ICNS file, you can delete the .iconset
directory.