Example #1
0
 /** 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) {
     }
 }
        $jobs = array();
        foreach ($urls as $url) {
            try {
                echo "Adding url: {$url}\n";
                $j = $webthumb->addUrl($url, 'medium2', 1024, 768);
                $j->file = str_replace(array(':', ':', '/', '&'), '_', substr($url, 7));
                $jobs[$i] = $j;
                $i++;
            } catch (Exception $e) {
                echo "Error adding a url -- " . $e->getMessage() . "\n";
            }
        }
        echo "Requesting {$i} thumbs\n";
        $webthumb->submitRequests();
        while (!$webthumb->readyToDownload()) {
            sleep(12);
            echo "Checking Job Status\n";
            $webthumb->checkJobStatus();
        }
        // while (!$webthumb->ready_to_download())
        $webthumb->fetchAll('thumbs');
        foreach ($webthumb->failedJobs as $url => $job) {
            echo "No job submitted for: {$url}\n";
        }
    } catch (Exception $e) {
        //    var_dump($e);
        echo "Exception handler\n";
        echo $e->getMessage();
        echo "\n\n";
    }
}