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
Examples:
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 Preview.app 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.
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>
(source)
A slightly different way:
sips -i myimg.icns (does work with all kinds of images, not just icns)DeRez -only icns myimg.icns > tmpicns.rsrcRez -append tempicns.rsrc -o targetfile.fooSetFile -a C targetfile.foocat targetfile.foo/..namedfork/rsrc(thanks web!)
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.