imagick convert to ico fails for some files

958 views Asked by At

here I have to cache about 2000 favicon.ico files for performance enhancements. I grab the files and try to shrink them via IMagick (v.6.6.0) and PHP 5.3.5 The PHP code for this is

try {
$image = new Imagick($im_hint . ':' . BASE . '/upload/favicon.ico');
$image->cropThumbnailImage(16, 16);
$image->setImageFormat('ico');
$image->writeImage(BASE . '/favicons/' . $id[0] . '/' . $id[1] . '/' . $id[2] . '/' . $id . '.ico');
} catch (Exception $e) { die($e->getMessage()); }

where $im_hint could be ico, png, jpg and so on. For 99% of the files all is fine and I get a working ICO file. But for one percent of files, I get only a blank ICO file and I don't know why? An example for an ICO file where this code fails is http://www.augensound.de/favicon.ico I tried to comment out the cropThumbnailImage call and try to use setFormat instead of setImageFormat and tried to save it as PNG...but nothing works. There is also no exception.

Regards

1

There are 1 answers

1
Pekka On

Not an answer to your question, but I get a blank image too when I open the example file in IrfanView or PhotoImpact. It's not a multi-page/multi-resolution file so there is nothing to switch. The canvas just is blank.

Windows 7's built-in preview renders it fine, though.

It could be that IM can't deal with these files because they have the wrong format or sub-format.