Package: icnsutil
icnsutilA fully-featured python library to handle reading and writing.icnsfiles.InstallThe easy way is to use the PyPi.org index:pip3installicnsutilOr you can install itmanuallyby creating a symlink tocli.py:ln-s'/absolute/path/to/icnsutil/icnsutil/cli.py'/usr/local/bin/icnsutil
ln-s'/absolute/path/to/icnsutil/icnsutil/autosize/cli.py'/usr/local/bin/icnsutil-autosizeOr call the python module (if the module is in the search path):python3-micnsutil
python3-micnsutil.autosizeUsageSee#toolsfor further options on icns processing (e.g., autosize).positional arguments:
  command
    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)# extracticnsutileExisting.icns-o./outdir/# composeicnsutilcNew.icns16x16.png16x16@2x.png*.jp2--toc# updateicnsutiluExisting.icns-rmtocic04ic05
icnsutiluExisting.icns-setis32=16.rgbdark="dark icon.icns"icnsutiluExisting.icns-rmdark-setic04=16.argb-oUpdated.icns# printicnsutiliExisting.icns# verify valid formaticnsutiltExisting.icns# convert imageicnsutilimg1024.png512@2x.jp2# or reuse original filenameicnsutilimgargb16x16.png
icnsutilimgrgb32.png
icnsutilimgpng16.rgb16.maskUse python libraryimporticnsutil# extractimg=icnsutil.IcnsFile('Existing.icns')img.export(out_dir,allowed_ext='png',recursive=True,convert_png=True)# composeimg=icnsutil.IcnsFile()img.add_media(file='16x16.png')img.add_media(file='16x16@2x.png')img.write('./new-icon.icns')# updateimg=icnsutil.IcnsFile('Existing.icns')img.add_media('icp4',file='16x16.png',force=True)ifimg.remove_media('TOC '):print('table of contents removed')img.write('Existing.icns',toc=True)# print# return type strdesc=icnsutil.IcnsFile.description(fname,indent=2)print(desc)# verify valid format# return type Iterator[str]itr=icnsutil.IcnsFile.verify(fname)print(list(itr))# 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 PNGYou can use the library without installing PIL.
However, if you want to convert between PNG and ARGB files, Pillow is required.pipinstallPillowimporticnsutil# Convert from ARGB to PNGicnsutil.ArgbImage(file='16x16.argb').write_png('16x16.png')# Convert from PNG to 24-bit RGBimg=icnsutil.ArgbImage(file='32x32.png')withopen('32x32.rgb','wb')asfp:fp.write(img.rgb_data())withopen('32x32.mask','wb')asfp:fp.write(img.mask_data())Note: the CLIexportcommand will fail if you run--convertwithout Pillow.ToolsAutosizeicnsutil.autosizeis 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 (viaresvgor Chrome Headless).icnsutil-autosizeicon.svg-32intermediate.png-16small.svg# orpython3-micnsutil.autosizeicon.svg-32intermediate.png-16small.svgAdditionally,autosizewill 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 runImageOptimto compress the images and reduce the overall icns filesize.HTML icon viewerHere 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.Theinspectorshows the structure of an icns file (useful to understand byte-unpacking in ARGB and 24-bit RGB files).Theviewerdisplays icons in ARGB or 24-bit RGB file format.Help neededDo you have an old macOS version running somewhere?You can help and identify what file formats / icns types were introduced and when. Download theformat-support-icns.zipfile and report back which icons are displayed properly and in which macOS version.See theApple Icon Imagewikipedia article.You can runmake sys-icons-testand report back whether you find some weird icons that are not handled properly by this library.