This is also useful for accurately converting .ico files to .png. (Other types as well, in theory, but I've only tested ico->png.) Simply using setFormat will create a valid .png file, but will result in image artifacts if the original .ico had any transparency. The following code will create an accurate copy:
<?php
$im = new Imagick();
$im->setFormat("ico");
$im->readImage("favicon.ico");
$im = $im->flattenImages(); $im->setFormat("png");
$new = fopen("favicon.png", "w");
$im->writeImageFile($new);
$im->clear();
$im->destroy();
?>