/** * Get the new url thumbnail * * This method fetches an image (thumb) to a file. * * @return integer The id of the job */ public function get() { while (!$this->webthumb->readyToDownload()) { sleep(1); $this->webthumb->checkJobStatus(); } $this->webthumb->fetchToFile($this->job, null, null, CUSTOM_MODEL . '/images'); return $this->job->status->id; }
/** Use bluga webthumb generate service **/ public function blugaWebThumbs($fileNames, $urls, $user_id = '') { require_once BASEPATH . 'libraries/Bluga/Autoload.php'; $postRequest = false; $apiKey = '0ead01a59d8f241798b9f8827871a365'; $dir = $path = $this->config->item('csv_upload_path'); if ($user_id != '' && !is_dir($dir)) { mkdir($dir, 0777); chmod($dir, 0777); } try { $webthumb = new Bluga_Webthumb(); $webthumb->setApiKey($apiKey); $i = 0; $jobs = array(); $count = 0; foreach ($urls as $url) { try { if (!file_exists($dir . $fileNames[$i] . '.png')) { //echo "File not exists if ".$dir.$fileNames[$i].'.png'; $j = $webthumb->addUrl($url['url'], 'large', 1200, 900, $url['width'], $url['height']); $j->file = $fileNames[$i]; $jobs[$count++] = $j; $postRequest = true; } else { //echo "File not exists else"; } } catch (Exception $e) { echo $e->getMessage(); } $i++; } if ($postRequest) { $webthumb->submitRequests(); while (!$webthumb->readyToDownload()) { //@ob_flush(); //flush(); sleep(6); //echo "<font color='red'>Checking Job Status For graph Thumb</font><br>\n"; $webthumb->checkJobStatus(); } $webthumb->fetchAll($dir); foreach ($webthumb->failedJobs as $url => $job) { echo "No job submitted for: {$url}\n"; } } //echo "FILENAME : ".$fileNames[0]; return $fileNames[0]; } catch (Exception $e) { } }
<pre> <?php // bring in your configuration, api yet etc require_once 'config.php'; ini_set('max_execution_time', 90); $url = 'http://webthumb.bluga.net/'; try { $webthumb = new Bluga_Webthumb(); $webthumb->setApiKey($APIKEY); $job = $webthumb->addUrl($url, 'medium2', 1024, 768); $webthumb->submitRequests(); while (!$webthumb->readyToDownload()) { sleep(5); echo "Checking Job Status\n"; $webthumb->checkJobStatus(); } // while (!$webthumb->ready_to_download()) $webthumb->fetchToFile($job); echo '<img src="' . $job->status->id . '.jpg' . '" /><br />'; } catch (Exception $e) { var_dump($e->getMessage()); } ?> </pre>