/** * 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; }
<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 // 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"; }
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>
$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'); $tmp = file('meta.txt'); $last = array_pop($tmp); if (preg_match('/render_time/', $last)) { echo "New renderer\n"; } else { echo "Old renderer\n"; } } catch (Exception $e) { var_dump($e->getMessage()); } } ?>