Code: Delicious.com + Thumbalizr screenshots + caching

I’m playing with my Delicious Snapcasa code this weekend to see if I can replace Snapcasa with the thumbalizr.com screenshot-service. Snapcasa was great because it gave me plenty of free captures each month, but it has some serious problems capturing some of the sites I throw at it, and was behaving rather randomly, so it has to go.

I’ve looked at several screen shot services, and tested many, and so far it is thumbalizer.com that seem to be the fastest and most stable, and the free version is able to take screenshots of webpages deeper into the site, not just the front page. As far as I can see I can’t find any limit on the api, but the free version does have a watermark on each thumb. I’m too cheap to spring for a paid account, but you do have that option.

The result so far

Demo: http://pappmaskin.no/opensource/delicious_snapcasa/delicious_thumbalizr.php?tag=art&count=100
Shows: The last 100 bookmarks tagged with “art” on delicious.com by me.

Caching

Thumbalizr.com provides a .gz with some php for caching the thumbnails their API provides, but I wasn’t able to get it to work last night. Luckily Anton Lindquist has branched the code on GitHub and made some improvements, and after a little headscratching (aka googleing) and some helpful tips from Anton himself, I am now running a version that grabs the images from Thumbalizer and stores them locally on my server, speeding up the pages quite a lot, easing the stress on thumbalizer, and most importantly, preventing already grabbed pages from being queued again and again.

New default queue image

Thumbalizr provides an OK queue-image while their services works on grabbing a screen shot of the page you request but with some help from Anton I’m not using my own custom image, currently a picture of my son holding a fish (just to make him smile :). It’s nice to have a little more control over what is displayed on the page until the image is ready for use, especially when you do like me and fire off a grid of many screen shots on the same page.

Possible uses

I’ve rewritten my original Snapcasa script into a WordPress plugin which I use on several of my blogposts right now. I’ve also made a standalone page for my sons, a start page with kid friendly games and YouTube-videos etc. They can’t read yet, so it’s nice to have an automated start page with pictures.

The code

I promised to update this post with the code I use for working with the Thumbalizr api and caching images locally. As I said I use this caching script instead of the code provided by Thumbalizr. It comes with an example index.php, that I’ve expanded on a little. Right now it looks like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 'api_key',
	'local_cache_expire' => (!$config['local_cache_expire']) ? 3600 : $config['local_cache_expire'],
 
);
$image = new thumbalizrRequest($config);
 
$image->request($imageurl);
 
//$image->request('http://www.thumbalizr.com/');
 
if($image->headers['Status'] == 'OK' || $image->headers['Status'] == 'LOCAL') {
	$image->output();
} else {
	//print_r($image->headers); //debug
//http://pappmaskin.no/wp-content/2010/03/noah-2624545080_417ba06836_m.jpg
 
$filename = 'http://pappmaskin.no/wp-content/2010/03/noah-2624545080_417ba06836_m.jpg';
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
    header("Content-type: {$size['mime']}");
    fpassthru($fp);
    exit;
} else {
    // error
}
 
}
 
?>

The last 9 bookmarks tagget with “wordpress” and “webdev”

Screenshot for http://www.infinite-scroll.com/

Infinite Scroll | jQuery plugin, Wordpress plugin, interaction design pattern

Screenshot for http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/

5 Tips For Using jQuery with WordPress / Eric Martin / ericmmartin.com

Screenshot for http://wpcandy.com/articles/tutorials/tutorial-adding-buttons-to-the-post-editor.html

Tutorial: Adding Buttons To The Post Editor — WPCandy — WordPress Themes, Plugins, Tips, and Tricks

Screenshot for http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

Including jQuery in WordPress (The Right Way) | Digging into WordPress

Screenshot for http://wordpress.org/extend/plugins/stray-quotes/

WordPress › Stray Random Quotes « WordPress Plugins

Screenshot for http://lorelle.wordpress.com/2007/02/28/random-wordpress-plugins-rotating-banners-header-art-images-quotes-and-content-on-your-blog/

Random WordPress Plugins: Rotating Banners, Header Art, Images, Quotes, and Content on Your Blog « Lorelle on WordPress

Screenshot for http://sojoe.info/2006/10/17/jpf-quotes-wordpress-plugin/

JPF Quotes WordPress Plugin | So Joe...

Screenshot for http://www.onextrapixel.com/2010/03/19/practical-uses-for-the-post-thumbnail-function-in-wordpress-2-9/

Practical Uses for the Post-Thumbnail Function in WordPress 2.9 | Onextrapixel - Showcasing Web Treats Without Hitch

Screenshot for http://planetozh.com/blog/2008/06/wordpress-plugin-coding-tips/

WordPress Plugin Coding Tips « planetOzh