Skip to main content

A fully-featured python library to handle reading and writing icns files.

Project description


A fully-featured python library to handle reading and writing .icns files.


The easy way is to use the index:

pip3 install icnsutil

Or you can install it manually by creating a symlink to

ln -s '/absolute/path/to/icnsutil/icnsutil/' /usr/local/bin/icnsutil
ln -s '/absolute/path/to/icnsutil/icnsutil/autosize/' /usr/local/bin/icnsutil-autosize

Or call the python module (if the module is in the search path):

python3 -m icnsutil
python3 -m icnsutil.autosize


See #tools for further options on icns processing (e.g., autosize).

positional arguments:
    extract (e)   Read and extract contents of icns file(s).
    compose (c)   Create new icns file from provided image files.
    update (u)    Update existing icns file by inserting or removing media entries.
    info (i)      Print contents of icns file(s).
    test (t)      Test if icns file is valid.
    convert (img) Convert images between PNG, ARGB, or RGB + alpha mask.

Use command line interface (CLI)

# extract
icnsutil e Existing.icns -o ./outdir/

# compose
icnsutil c New.icns 16x16.png 16x16@2x.png *.jp2 --toc

# update
icnsutil u Existing.icns -rm toc ic04 ic05
icnsutil u Existing.icns -set is32=16.rgb dark="dark icon.icns"
icnsutil u Existing.icns -rm dark -set ic04=16.argb -o Updated.icns

# print
icnsutil i Existing.icns

# verify valid format
icnsutil t Existing.icns

# convert image
icnsutil img 1024.png 512@2x.jp2
# or reuse original filename
icnsutil img argb 16x16.png
icnsutil img rgb 32.png
icnsutil img png 16.rgb 16.mask

Use python library

import icnsutil

# extract
img = icnsutil.IcnsFile('Existing.icns')
img.export(out_dir, allowed_ext='png',
           recursive=True, convert_png=True)

# compose
img = icnsutil.IcnsFile()

# update
img = icnsutil.IcnsFile('Existing.icns')
img.add_media('icp4', file='16x16.png', force=True)
if img.remove_media('TOC '):
    print('table of contents removed')
img.write('Existing.icns', toc=True)

# print
# return type str
desc = icnsutil.IcnsFile.description(fname, indent=2)

# verify valid format
# return type Iterator[str]
itr = icnsutil.IcnsFile.verify(fname)
# If you just want to check if a file is faulty, you can use `any(itr)` instead.
# This way it will not test all checks but break early after the first hit.

Converting between (A)RGB and PNG

You can use the library without installing PIL. However, if you want to convert between PNG and ARGB files, Pillow is required.

pip install Pillow
import icnsutil

# Convert from ARGB to PNG

# Convert from PNG to 24-bit RGB
img = icnsutil.ArgbImage(file='32x32.png')
with open('32x32.rgb', 'wb') as fp:
with open('32x32.mask', 'wb') as fp:

Note: the CLI export command will fail if you run --convert without Pillow.



icnsutil.autosize is a tool to automatically generate smaller icon sizes from a larger one. Currently, autosize has support for “normal” raster images (via sips or Pillow) and SVG images (via resvg or Chrome Headless).

icnsutil-autosize icon.svg -32 intermediate.png -16 small.svg
# or
python3 -m icnsutil.autosize icon.svg -32 intermediate.png -16 small.svg

Additionally, autosize will also try to convert 32px and 16px PNG images to ARGB. If Pillow is not installed, this step will be skipped (without negative side effects). The output is an iconset folder with all necessary images.

You may ask why this tool does not create the icns file immediatelly? This way you can modify the generated images before packing them into an icns file. For example, you can run ImageOptim to compress the images and reduce the overall icns filesize.

HTML icon viewer

Here are two tools to open icns files directly in your browser. Both tools can be used either with an icns file or a rgb / argb image file.

  • The inspector shows the structure of an icns file (useful to understand byte-unpacking in ARGB and 24-bit RGB files).
  • The viewer displays icons in ARGB or 24-bit RGB file format.

Help needed

  1. Do you have an old macOS version running somewhere?
    You can help and identify what file formats / icns types were introduced and when. Download the file and report back which icons are displayed properly and in which macOS version.
    See the Apple Icon Image wikipedia article.

  2. You can run make sys-icons-test and report back whether you find some weird icons that are not handled properly by this library.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icnsutil-1.1.0.tar.gz (23.7 kB view hashes)

Uploaded source

Built Distribution

icnsutil-1.1.0-py3-none-any.whl (26.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page