Code: Delicious.com + Thumbalizr screenshots + caching

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /customers/7/5/b/pappmaskin.no/httpd.www/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

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: https://pappmaskin.no/opensource/delicious_snapcasa/delicious_thumbalizr.php?tag=art&count=10
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
//https://pappmaskin.no/wp-content/2010/03/noah-2624545080_417ba06836_m.jpg
 
$filename = 'https://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»

[deliciousthumbs tag=»wordpress+webdev» count=»9″]

Av Morten Skogly

Creator of Things

5 kommentarer

  1. I know this is an old post, but I just ran across it.
    When I try to use your script, I get a strange problem.. It says that it cannot modify header information.
    Have you come across this error before? Any help would be greatly appreciated. Thanks!

Kommentarer er stengt.