Sep
29
2006
Using thumbshots.org with ASP.NET and C# part 1
Posted by admin under
Controls
Ever heard of thumbshots.org ? They offer a (free) service letting you retrieve thumbnail images from websites and webpages for use in your own web pages. Pretty cool and so easy to use:
In short - you just point your images to their handler and add your specific url at the end:
<img src="http://open.thumbshots.org/image.pxf?url=http://www.aspcode.net">
retrieves this image:
(rightclick and check the address)
Now - lets build something out of this. While the performance of thumbshots.org seems pretty fantastic it's always good with more control - so my idea is to create an image handler in ASP.NET 2.0 which would cache the files on our own server.
I.e the img src would then look like this
<img src="http://yoursite.com/thumbshot.ashx?url=http://www.aspcode.net">
First time called (for each specific url) the handler (thumbshot.ashx) will download the file from thumbshots.org to our local disk - and next requests will simple use that local file instead. We will add a "cache dependency" - so after X number of days we will receive a new file.
Lets start by looking at the demo page:

Enter any url - and after clicking the "Button" the image will update to show the thumbshot. That is solved codebehind by setting the ImageUrl to the textbox value:
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "thumbshot.ashx?u=" + TextBox1.Text;
}
Please read part 2 - the download file is there as well.
Thumbnails by Thumbshots.net