Since Alexa stopped offering their free thumbnail service last year a lot of thumbnail services are available now. Some of them offering limited free services and others only a paid premium version. On of the bigger and better services is Girafa, a thumbnail service with a free service and also premium services for users with more then 2000 image requests a month.

Joining the service for free is fast and easy, within an hour my account was up and well.
With a special Thumbnail URL Generator it’s possible to create the URL for a thumbnail from a website in no time, just enter the URL from the website and you get some code like this:

Client ID: j35jh34k5j
URL: http://girafa.com
Signature Key: 34u3gh45k4hk
Concatenated String: gh345gi6dfjhttp://girafa.com
MD5 Hash: d619bc0b9568adfe9f779359e3212f
Signature: 9f7ce2e6e9e3212f
Thumbnail URL: http://scst.srv.girafa.com/srv/i?i=j35j…&r=http%3A%2F%2Fgirafa.com&s=34…

This information is OK if you add only a few thumbs to your homepage, but what if you need a dynamic function? The next function will do the job in PHP without using the thumbnail generator from the Girafa website.

function thumbnail($url) {
	$client_id = 'urrjr7894784'; // your client ID
	$signature = 'kjhh35h4j5'; // the signature you entered @ girafa
	$concatenated = $signature.$url;
	$MD5_Hash = md5($concatenated);
	$signature = substr($MD5_Hash, 16, 16);
	$url = urlencode($url);
	$str = 'http://scst.srv.girafa.com/srv/i?i=';
	$str .= $client_id .'&r='. $url .'&s='. $signature;
	return $str;
}

This function returns a complete URL based on the argument you have passed to the function.

How does it work?
First the signature you entered via the Girafa website is concatenated to the URL, on the next code row there is a MD5 hash created from the string (signature+url). With the PHP function substring the string is shortened into the last 16 characters and this new string is used as a value for the variable $signature. Next you need to urlencode the URL and at the end the function returns a string with all required values. The result is a same type of URL which is created with the thumbnail generator from the Girafa website.

What if 2000 thumbnail requests are not enough?
First of all you can buy as much as thumbnails you need. If you don’t have a budget for this premium service, it’s possible to cache the thumbnails on your own web server with this kind of code:

$dom_parts = parse_url($url);
$thumb = 'doc_root/your_thumb/'.$dom_parts['host'].'.jpg';
if(!@file_exists($thumb)) {
	// next you will use your function
	$request_for = thumbnail($url);
	@copy($request_for, $thumb);
}

Check this website to get an idea how you can use it.