What is an ICNS File?
An ICNS file is an Apple container for application icon resources. It can hold multiple icon dimensions, resolutions, and pixel representations used by macOS.
How ICNS Files work
An ICNS file groups the representations of one macOS icon for different display sizes and pixel densities. As implemented in Pillow’s reader, the file begins with the four bytes icns and a big-endian total length, followed by elements that each start with a four-character type code and a length. The type code identifies the representation: ic07 is the 128-point icon, for example, and ic10 the 512-point icon at 2x scale. Apple’s tooling builds the file from a folder with the .iconset extension that contains PNGs named by point size and scale. The iconutil command converts that folder into an ICNS file and back, and Apple’s archived 2012 guidance says Xcode 4.4 converts an iconset folder in a project automatically when the project is built. The bundle’s Info.plist names the icon file through the CFBundleIconFile key.
Key facts
- Which sizes belong in the file? Apple’s iconset convention uses five point sizes (16, 32, 128, 256, and 512), each at standard and
@2xscale, so the largest image is 1024 by 1024 pixels and is namedicon_512x512@2x.png. The set does not have to be complete: Apple’s guidance says the system chooses the best representation for sizes you do not supply. It also saysicon_16x16@2x.pngandicon_32x32.pngare not equivalent although they have the same pixel count, because they appear at different sizes on screen and may need different detail. This guidance dates from 2012 and is in Apple’s documentation archive. - What is inside each element? It depends on the type code, so a parser has to handle more than one payload form. In Pillow’s reader, the
ic07toic14andicp4toicp6elements each hold a complete PNG or JPEG 2000 image, while older types such asis32andil32hold RGB data, either raw or run-length encoded, with the alpha channel in a separate 8-bit mask element such ass8mkorl8mk. This matters for tools that reuse an ICNS file as an image source: electron-builder’s documentation says it extracts the largest embedded PNG frame when an ICNS file is the icon source for another platform. One user reported a Linux build that stopped with ‘Could not extract a PNG frame from ICNS file’ after the tool changed its icon converter, and worked around it by supplying a PNG for the Linux build. The report does not establish what in that file caused the failure, and a maintainer later said a new release of the converter should fix it. - How do I create or inspect one? On macOS,
iconutil -c icnsconverts an.iconsetfolder to an ICNS file andiconutil -c iconsetconverts an ICNS file back into its PNGs; Apple’s guidance says the iconset images must be square, with dimensions that match their file names. Off macOS, Pillow can write ICNS files on any operating system since version 8.3.0. Its writer scales the image you save to a square at each size you do not pass throughappend_images, and its save code does not check that the source is square or 1024 pixels wide. It matches the images inappend_imagesby pixel width, so two elements with the same pixel size share one image. It writes only theic07toic14elements, 32 to 1024 pixels wide: the 32-pixel image is stored as the 16-point icon at 2x scale, and there is no element for the 16-point or 32-point icon at standard scale. Apple’s guidance is to design the large icon first and then decide how to scale it down, adjusting an icon where needed for the size and pixel density at which it appears.
When ICNS Files matter
An ICNS file matters when a macOS application bundle is assembled outside Xcode’s asset pipeline, for example by a cross-platform packaging tool. You may not have to build the file yourself: electron-builder’s documentation says it uses a prebuilt .icns file as-is and can also convert a PNG or SVG source, generating every size from that one input. Supply your own file when your tool requires one or when you want to control the artwork at each size. Inside Xcode, Apple’s current documentation has you provide the app icon through an asset catalog or an Icon Composer file instead. Apple’s archived 2012 guidance says a complete set of sizes is recommended but not required: macOS chooses the best available representation for a size you leave out, which means that size is shown from artwork drawn for a different one.
Sources
- Apple documentation archive: Optimizing for High Resolution (iconset sizes, iconutil, Xcode conversion)
- Apple: CFBundleIconFile information property list key
- Apple: Configuring your app icon using an asset catalog
- Apple: Creating your app icon using Icon Composer
- Pillow source: IcnsImagePlugin.py (ICNS element types and payloads)
- Pillow handbook: ICNS reading and saving
- electron-builder documentation (v26): Icons & Images (accepted icon inputs, ICNS conversion)
- electron-builder issue 9876: Could not extract a PNG frame from ICNS file