Skip to content
Advertisement

Convert ICO to PNG using PHP Imagick

I am currently trying to convert an ICO file to a 16×16 px PNG, using PHP-Imagick. What I’ve tried so far:

JavaScript

This works partially. The problem is, that an ICO file may contain multiple images, so the code above creates multiple PNG files

  • favicon-0.png
  • favicon-1.png

for every size. This is okay, but then, I need the possibility to find the one that is close to 16×16 px, scale it down (if needed) and delete all others. For this, I already tried some things and this is where I’m stuck currently:

JavaScript

I guess, i would find a working way with some trial and error. But I would like to know, if there’s an easier way to achieve this.

TL;DR: I need a simple way to convert an ICO file of any size to a 16×16 px PNG, using PHP-Imagick (using GD isn’t an option).

Update:

My (currently working but maybe suboptimal) solution:

JavaScript

Advertisement

Answer

My final solution:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement