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: 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.

 '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
}

}

?>

Fortsett å lese «Code: Delicious.com + Thumbalizr screenshots + caching»

Delicious Screenshots – my first wordpress plugin

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /customers/7/5/b/pappmaskin.no/httpd.www/wp-content/plugins/delicious_screenshots/wp_delicious_sceenshots.php on line 75Warning: file_get_contents(http://feeds.del.icio.us/v2/json/mskogly/art?Fcount=6): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /customers/7/5/b/pappmaskin.no/httpd.www/wp-content/plugins/delicious_screenshots/wp_delicious_sceenshots.php on line 75Warning: Invalid argument supplied for foreach() in /customers/7/5/b/pappmaskin.no/httpd.www/wp-content/plugins/delicious_screenshots/wp_delicious_sceenshots.php on line 79

If this works there should be about 6 thumbnails on this page, showing links bookmarked using Delicious, and tagged with “art”.


Download:
Download delicious_screenshots.zip here, version 0.7 of my very first wordpress plugin.

Usage:
Activate plugin. And add your del.icio.us username to the options page. (under settings in the WordPress toolbar)
https://i2.wp.com/pappmaskin.no/wp-content/2011/07/20081020-jq6mtqhq3k4pu475bffhjuppcs.jpg?w=525

Changelog:
14.02.2017: Changed from rss to json and cleaned the code up a bit. Also removed Snapcasa from options.

What’s next:

  1. The first version of this plugin used Snapcasa for creating thumbnails, but I switched to thumbalizr.com to get a higher success rate.
  2. The count param doesn’t seem to do anything when calling the del.icio.us api, it always returns 10 results, so I need to handle that in the code instead. I’ve notified them of the bug.
  3. Testing other screenshotting services or making my own.
  4. Choosing an image from the page metadata when available.

Playing with SnapCasa screenshots and del.icio.us

https://i0.wp.com/pappmaskin.no/wp-content/2011/07/20081016-es6718uspgixxfa8x8d7kbqm8y.jpg?resize=480%2C354

Tonights nerdfest will include trying to use the SnapCasa and del.icio.us to generate a lovely page full of thumbnails, one for each url.

Ingredients:

1. My 100 latest bookmarked urls from del.icio.us: http://feeds.delicious.com/v2/rss/mskogly?count=100
2. A SnapCasa login account.
3. A server that supports xslt transformation. (I’m running MAMP on my macbook, and pappmaskin is hosted on One.com)
4. A text editor. I’m using Dreamweaver for this, since it has some pretty good tools for building xslt. (Take a look at the Adobe Livedocs for more info on using it).

(More after the break)

Fortsett å lese «Playing with SnapCasa screenshots and del.icio.us»