Generating Thumbnail Using SnapCasa
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:
- CODE
value to “User Code” which will be provided once you are registered with SnapCasa.com - LOCATION
path location where you want to store the image, for this example I’m using c:/xamp/htdocs/ - 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");
Snapcasa provides much more accurate website thumbnails than the last provider I used. Thanks for the code and the link.