I’m happy to report that PHP ICO is now live on GitHub.

For the past couple of weeks, I have worked on creating a PHP library to create ICO files. This has been difficult as all the documentation for the ICO format is either sparse or not completely documented.

I’m doing this since I have yet to find a way of creating a valid favicon file using just PHP and PHP’s GD library. Sure, I can create a PNG file and change the extension to “.ico”, but that doesn’t work in all browsers, on all operating systems (such as Windows XP), and is more of a hack than a valid method for creating favicon files.

So, it is time to make one. I have a placeholder github repository named php-ico.

The primary goal is to make a robust, reliable library that creates valid ICO files that can be properly rendered on Windows XP+ and all the major browsers. Thus, my initial goal is not to support every format that exists nor is it to support parsing the ICO files. If the project gets enough attention, I’ll look at expanding the scope.

Here are the resources that I’ve found helpful as I’ve worked on this project:

  • ICO (file format) – Wikipedia article about the ICO file format. This has a very comprehensive description of the ICO header. It is sparse on details about the format of the image data.
  • BMP file format – Wikipedia article about the BMP file format. This helped me understand the headers and pixel data format for the BMP image data.
  • Portable Network Graphics – Wikipedia article about the PNG file format. This gave me what I needed to know to identify PNG image data.
  • Windows Bitmap File Format – Very good article that delves into more details about the BMP file format. The extra details about the different types of headers, compression methods, compression encoding, and examples were very helpful.
  • Icons – A Microsoft Developer Network article from 1995 that provides the original ICO file format spec. While this is the most authoritative, I really didn’t find this to be as much help as other sources.
  • Replacing ICON resources in EXE and DLL files – Article from The Code Project that has a breakdown of the format similar to what is found in the MSDN article. Example C code is provided.
  • Support Vista-style ICO files – Mozilla Bugzilla filed bug. The discussion has some great information about methods used to reliably parse varying ICO formats and structures. It also has some good test ICO files to try.
  • Convert HBITMAP to .ICO file – This Chironex Software blog post provided the last piece I needed: how to structure the opacity mask data. Where he found this information (since I didn’t find it in any of the above articles) I haven’t a clue.

If this post gets some traction and interest, I’ll consider putting together a post detailing all the different pieces I’ve found here. I’m not a spec writer, but I’d try my best. Let me know if you’d like to have me work on this.

Did I help you?