I've been using <http://tools.dynamicdrive.com/favicon/> for years now for generating favicons. I started using it before I even knew how to do any coding (I'm not great now). I don't mind using the utility because the icons always look pretty good, but I'd love to be able to do it locally.

How can I create a favicon locally with a script? Somehow with PHP, imagemagick / gd or maybe sips from the command line?