Exemple #1
0
 /**
  * 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;
 }
Exemple #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());
<?php

// fix this include if you aren't running from the examples dir
require_once '/home/jeichorn/sandbox/Bluga/trunk/Bluga/PEAR2/Autoload.php';
// put config.php in the same dir as the notify script or
if (file_exists(dirname(__FILE__) . '/config.php')) {
    include 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";
}
file_put_contents("/tmp/notify_post.log", json_encode($_GET) . "\n" . json_encode($_POST) . "\n");
if ($_GET['notify_key'] != $NOTIFY_KEY) {
    echo "Oh no someone is trying to hack me\n";
} else {
    // download the key, use fetch api
    $webthumb = new Bluga_Webthumb();
    $webthumb->setApiKey($APIKEY);
    $job = new Bluga_Webthumb_Job();
    $job->status['id'] = $_POST['id'];
    $webthumb->fetchToFile($job, $OUTPUT_DIR . "/" . $_GET['file'], $THUMB_SIZE);
    echo "Wrote file to: " . $OUTPUT_DIR . $_GET['file'] . "\n";
    echo "And everything worked\n";
}
<?php

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);
// 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);
<?php

// this example generates 3 urls, setting the renderer option based on config and checks the meta file output to see if the new renderer is being used
// bring in your configuration, api yet etc
require_once 'config.php';
ini_set('max_execution_time', 90);
$urls = array('http://amazon.com/' => false, 'http://slashdot.org' => 5, 'http://google.com/' => false);
foreach ($urls as $url => $renderer) {
    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 ($renderer !== false) {
            $job->options->renderer = $renderer;
        }
        echo "Submitting {$url} renderer: {$renderer}\n";
        // 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, 'meta.txt', 'meta');