makeicns – Create icns files from the command line

Screenshot of an icns file with 512x512 and 32x32 variants.

This program lets you convert all kinds of images to Apple's icns format on the command line. As far as I know, there is no other tool which does this (tiff2icns doesn't support Leopard's 512x512 icons, and it only supports tiff input, too).

Download! (universal binary, source included)

If you want to create document icons, you want to use docerator.

If you prefer a program with a GUI for the same purpose, use img2icns.

Here's how to use it:

$ ./makeicns 
makeicns v1.1 (20090413)

Usage: makeicns [k1=v1] [k2=v2] ...

Keys and values include:
    512: Name of input image for 512x512 variant of icon
    256: Name of input image for 256x256 variant of icon
    128: Name of input image for 128x128 variant of icon
     32: Name of input image for 32x32 variant of icon
     16: Name of input image for 16x16 variant of icon
     in: Name of input image for all variants not having an explicit name
    out: Name of output file, defaults to first nonempty input name,
         but with icns extension


  makeicns -512 image.png -32 image.png
      Creates image.icns with only a 512x512 and a 32x32 variant.

  makeicns -in myfile.jpg -32 otherfile.png -out outfile.icns
      Creates outfile.icns with sizes 512, 256, 128, and 16 containing data
      from myfile.jpg and with size 32 containing data from otherfile.png.

To convert an icns back to, say, a png either use or sips (sips -s format png icon.icns --out icon.png).

Last updated 20090413. Added a workaround around a bug in IconFamily (the icns library this program uses) – it cannot handle NSAlphaNonpremultipliedBitmapFormat images. Alpha masks are now handled correctly.

Original release 20081122.

By the way

If you want to set the icon resource of a file to a given image using the terminal, do the following:

echo "read 'icns' (-16455) \"<source.icns>\";" | /Developer/Tools/Rez -o <target_file>
/Developer/Tools/SetFile -a "C" <target_file>

To do the same for a folder, do:

echo "read 'icns' (-16455) \"<source.icns>\";" | /Developer/Tools/Rez -o `printf "<target_folder>/Icon\r"`
/Developer/Tools/SetFile -a "C" <target_folder>


A slightly different way:

  1. Copy an image into its own resource fork: sips -i myimg.icns (does work with all kinds of images, not just icns)
  2. Extract the icon resource into a file: DeRez -only icns myimg.icns > tmpicns.rsrc
  3. Copy the icon resource into the resource of your target file: Rez -append tempicns.rsrc -o
  4. Set the "file has custom icon" bit: SetFile -a C
  5. If you want, you can also look at the resource fork using cat

(thanks web!)

Also related.

If you don't like to use the terminal, you can go to the file/folder in Finder, open the Get Info dialog, and copy/paste the icon in there.