Esempio n. 1
0
 /**
  * Constructor
  *
  * This is the constructor for the Spaz_Thumb object. By passing
  * the URL to the constructor we add the url and submit a job on
  * the webthumb server.
  *
  * @param string $url  The URL to get the thumb about
  */
 public function __construct($url)
 {
     $this->webthumb = new Bluga_Webthumb();
     $this->webthumb->setApiKey(self::API_KEY);
     $this->job = $this->webthumb->addUrl($url, self::THUMB_SIZE, 1024, 768);
     $this->webthumb->submitRequests();
 }
Esempio n. 2
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) {
     }
 }
<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>

<?php

// this is a really simple notify example, not tracking of urls is done,
// the downside of this is its hard to prevent multi requests for the same url from being made
require_once dirname(__FILE__) . '/config.php';
// check for a config file in your home dir
// you can set the items above in .webthumb.php in your home dir
$home = getenv('HOME');
if (file_exists("{$home}/.webthumb.php")) {
    include "{$home}/.webthumb.php";
}
// setup a new Webthumb wrapper
$webthumb = new Bluga_Webthumb();
$webthumb->setApiKey($APIKEY);
if (!isset($argv[1])) {
    echo "php run.php url\nphp run.php http://bluga.net\n";
    die(1);
}
$url = $argv[1];
$j = $webthumb->addUrl($url, $THUMB_SIZE, 1024, 768);
$file = preg_replace('/[^A-Za-z0-9]/', '', $url) . "-" . date('YmdHis');
$j->options->notify = array('url' => $NOTIFY_URL . "?notify_key={$NOTIFY_KEY}&file={$file}", 'post' => 'true');
echo date('Y-m-d H:i:s') . ": Submitting " . count($webthumb->jobs) . " jobs\n";
$webthumb->submitRequests();
foreach ($webthumb->jobs as $job) {
    echo "Added " . $job->status['id'] . " at " . $job->status['start_time'] . "\n";
}
<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, 'excerpt', 1024, 768);
    // you can set any option here
    // see: http://webthumb.bluga.net/apidoc#request
    $job->options->excerpt = array('x' => 400, 'y' => 400, 'height' => 200, 'width' => 200);
    $job->options->outputType = 'png8';
    // 8bit png output, 32bit is type png (8bit can be lower quality but is smaller and is generally better quality then jpg)
    $job->options->fullthumb = true;
    $webthumb->submitRequests();
    while (!$webthumb->readyToDownload()) {
        sleep(5);
        echo "Checking Job Status\n";
        $webthumb->checkJobStatus();
    }
    // while (!$webthumb->ready_to_download())
    $webthumb->fetchToFile($job, $job->status->id . "-excerpt.png", 'excerpt');
    $webthumb->fetchToFile($job, null, 'full');
    echo 'Job Url: http://webthumb.bluga.net/pickup?id=' . $job->status->id . "\n";
    foreach (glob($job->status->id . '*') as $file) {
        echo "{$file}\n";
    }
} catch (Exception $e) {
    var_dump($e->getMessage());
<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);
    // set which image to download and browser size
    $job = $webthumb->addUrl($url, 'custom', 1024, 1024);
    // set the size of the custom thumbnail
    $job->options->customThumbnail = array('width' => 1024, 'height' => 1024);
    $job->options->fullthumb = 1;
    // if your making a lot of requests use notification, set it like
    // $job->options->notify = 'http://example.com/notify.php';
    // see bulk_with_db for a complete example
    $webthumb->submitRequests();
    // wait for the job to be finished and download, don't do this if you use notify
    while (!$webthumb->readyToDownload()) {
        sleep(5);
        echo "Checking Job Status\n";
        $webthumb->checkJobStatus();
    }
    $webthumb->fetchToFile($job);
    echo '<img src="' . $job->status->id . '.jpg' . '" /><br />';
} catch (Exception $e) {
    var_dump($e->getMessage());
}
?>
    include "{$home}/.webthumb.php";
}
// setup a new Webthumb wrapper
$webthumb = new Bluga_Webthumb();
$webthumb->setApiKey($APIKEY);
// setup db connection
$pdo = new PDO($DB_DSN, $DB_USER, $DB_PASSWORD);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// query the urls db
// you might want to make this more complex
$query = "select url_id, url from urls";
// make requests in batches of 50
// sleep a bit between to be nice
$batch = 0;
foreach ($pdo->query($query) as $row) {
    $j = $webthumb->addUrl($row['url'], $THUMB_SIZE, 1024, 768);
    $j->options->notify = $NOTIFY_URL . '?url_id=' . $row['url_id'];
    $j->user['url_id'] = $row['url_id'];
    if ($batch++ > 50) {
        $batch = 0;
        submitJobs($webthumb);
    }
}
submitJobs($webthumb);
function submitJobs($webthumb)
{
    global $pdo;
    // prepare a jobs statement for inserting
    $stmtJobs = $pdo->prepare("insert into jobs (job_id, url_id, start_time) values(?,?,?)");
    echo date('Y-m-d H:i:s') . ": Submitting " . count($webthumb->jobs) . " jobs\n";
    $webthumb->submitRequests();
<pre>
<?php 
// high quality fullsize output png thumbnail example
// 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);
    // -1 for auto height
    $job = $webthumb->addUrl($url, 'full', 1024, -1);
    // enable fullthumb
    $job->options->fullthumb = 1;
    $job->options->outputType = 'png';
    // if your making a lot of requests use notification, set it like
    // $job->options->notify = 'http://example.com/notify.php';
    // see bulk_with_db for a complete example
    $webthumb->submitRequests();
    // status webpage
    echo "http://webthumb.bluga.net/pickup?id={$job->status->id}\n";
    // wait for the job to be finished and download, don't do this if you use notify
    while (!$webthumb->readyToDownload()) {
        sleep(5);
        echo "Checking Job Status\n";
        $webthumb->checkJobStatus();
    }
    $webthumb->fetchToFile($job);
    echo '<img src="' . $job->status->id . '.jpg' . '" />' . "\n";
} catch (Exception $e) {
    var_dump($e->getMessage());