AnilKumar

Joined: 09 May 2008 Posts: 197
|
Posted: Mon Jan 25, 2010 12:37 pm Post subject: Creating thumbnail of webpage using webthumb API |
|
|
Hello,
1)create a api key for your application from http://webthumb.bluga.net/
2) The below function will request for thumbnail
function requestThumbnail($url = "", $width= "", $height = "")
{
$requests = "<url>{$url}</url>";
if (!empty($height))
$requests = "<height>{$height}</height>";
if (!empty($width))
$requests = "<width>{$height}</width>";
$requests = "<request>".$requests."</request>";
$_request = "<webthumb>
<apikey>{$this->_api}</apikey>
{$requests}
</webthumb>";
$_response = $this->_executeCurlRequest($_request);
$_sxml = simplexml_load_string($_response);
$_jobs = array();
foreach($_sxml->jobs->job as $job)
{
$_job = array("id"=>$job."",
"estimate"=>$job['estimate']."",
"time"=>$job['time']."",
"url"=>$job['url']."");
$_jobs[] = $_job;
}
return $_jobs;
}
3) To get that thumbnail run the below function which is using curl
function executeCurlRequest($request)
{
$_session = curl_init();
curl_setopt($_session, CURLOPT_URL, $request_uri); curl_setopt ($_session, CURLOPT_POST, 1);
curl_setopt ($_session, CURLOPT_POSTFIELDS, $request);
curl_setopt($_session, CURLOPT_HTTPHEADER,
array( 'Content-Type: application/xml'));
curl_setopt($_session, CURLOPT_RETURNTRANSFER, true);
$_response = curl_exec($_session);
return $_response;
}
Hope that this will be useful, but is limited to 100 thumbs for one month ( that is limited).
Thank you,
Anil Kumar Panigrahi  |
|