Generating Thumbnail Using SnapCasa

Posted on the June 5th, 2008 under PHP, Programming, Tutorial by Zaki

In this tutorial I will share with you on how to create a generated thumbnail of website store at your own webserver without having to depend on 3rd party provider to repeatly load thumbnails overtime. For the tutorial I will show you how to generate site thumbnail using PHP and SnapCasa.com.

The Code

Here the whole source code used to generate the thumbnail.

ini_set("display_errors", "on");
error_reporting(E_ALL);
 
define("CODE", "1"); // depend on what is "User Code" when you register with snapcasa.com
define("LOCATION", "c:/xamp/htdocs/"); // Location to store the thumbnail
define("SIZE", "L"); // size of the thumbnail: T, S, M, L
 
function generate_site($url) {
	$name = str_replace(".", "", $url);
	$thumb = LOCATION.$name.'.jpg';
	$request_for ='http://snapcasa.com/Get.aspx?code='.CODE.'&size='.SIZE.'&url=http://'.$url;
	copy($request_for, $thumb);
}

There’s only three (3) things that you need to edit in order to use the script:

  1. CODE
    value to “User Code” which will be provided once you are registered with SnapCasa.com
  2. LOCATION
    path location where you want to store the image, for this example I’m using c:/xamp/htdocs/
  3. SIZE
    SnapCasa.com only provide 4 thumbnail size; T, S, M or L.

What You Need To Do?

Create an account with SnapCasa.com to enable you to use their API, as mention above you will need to have the “User Code”. Additional you also need to specify where you intent to use the thumbnail but so far I have no problem using it in my localhost even without registrating it.

Secondly you also need to check whether your PHP Configuration enable use of allow_url_fopen in order for the copy() function to use URL instead of path.

Using the Code

For example you can use the code such as:

generate_site("www.chronosight.net");

One Response to 'Generating Thumbnail Using SnapCasa'

Subscribe to comments with RSS or TrackBack to 'Generating Thumbnail Using SnapCasa'.
  1. Mike said, on November 21st, 2008 at 9:50 am

    Snapcasa provides much more accurate website thumbnails than the last provider I used. Thanks for the code and the link.

  1. No trackback at the moment.
Leave a Reply
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">