ICO images in FaceBook profile boxes

So I’ve been developing a FaceBook application, My Sites. It let’s you bookmark websites you like and share them with your friends.

The Problem

When a FaceBook application tries to add HTML to someone’s profile box, it can add images, but only in JPG, GIF, or PNG formats. For most uses this is fine, but I needed to add a favicon next to each website in a list, and ICO format isn’t allowed.

The Solution

Using a free php class that can import ICO images to a GD image resource, I converted the favicons to PNGs. Now FaceBook is all happy. Download a ZIP of the icon class here, or directly from PHPclasses.org.

[EDIT: please see my post on the important bug fix]

The Code

Here’s how you use the class:


<?php
error_reporting(0);
require("ico.class.php");
$f = "http://www.google.com/favicon.ico";
$i = new Ico($f);
if(!($r=$i->GetIcon(0))) die("Could not load ICO.");
else {
          header("Content-Type: image/png");
          imagepng($r);
}
?>
  • Share/Bookmark

Tags: , , , , , , , ,

Leave a Reply