Exemple #1
0
function processDir($dir)
{
    $files = glob($dir . "/*");
    foreach ($files as $file) {
        $thumbnailer = new Thumbnailer(BASE_DIR);
        if (!$thumbnailer->generateThumb($file)) {
            echo "Failed to generate thumbnail" . PHP_EOL;
            exit;
        }
    }
}
Exemple #2
0
     } else {
         if (!$_SESSION['SelectedMovie']->valid()) {
             $action = 'selectMovie';
         } else {
             $action = 'movie';
         }
     }
 }
 $handler = null;
 switch ($action) {
     case 'json':
         $handler = new JSONHandler(Param('call'));
         break;
     case 'thumbnail':
         try {
             Thumbnailer::handleImageRequest();
         } catch (Exception $e) {
             // Error-Image
             header("Content-Type: image/jpeg");
             header("Cache-Control: no-cache, must-revalidate");
             print file_get_contents(dirname(__FILE__) . '/misc/error.jpg');
         }
         exit;
         break;
     case 'selectMovie':
         $handler = new MovieSelectorHandler();
         break;
     case 'showLicense':
         $handler = new LicenseHandler();
         break;
     case 'showChangelog':
define("XmlNodeTypeContent", 2);
// Application class files
include sgLIBRARY . "Utility.Functions.php";
include sgLIBRARY . "Utility.ErrorManager.class.php";
include sgLIBRARY . "Utility.Parameters.class.php";
include sgLIBRARY . "Utility.XmlManager.class.php";
include sgLIBRARY . "Utility.File.class.php";
include sgLIBRARY . "Filebrowser.Utility.php";
include sgLIBRARY . "Filebrowser.FileCollection.class.php";
include sgLIBRARY . "Filebrowser.Configuration.class.php";
include sgLIBRARY . "Filebrowser.Thumbnailer.class.php";
// Instantiate the Error manager
$ErrorManager = new ErrorManager();
$PageAction = ForceIncomingString("PageAction", "");
$DirectoryID = ForceIncomingString("did", "");
$tn = new Thumbnailer();
$tn->ConfigFile = "_config.xml";
$tn->ErrorManager =& $ErrorManager;
$tn->DefineProperties();
if ($PageAction == "Generate") {
    $ImagesLeftToThumbnail = $tn->GenerateThumbnails();
    if (count($ImagesLeftToThumbnail) == 0) {
        $PageAction = "Complete";
    }
}
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-ca\">\r\n<head>\r\n<title>Lussumo Thumbnailer</title>\r\n<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $tn->StyleUrl . "\" />\r\n<script language=\"Javascript\" type=\"text/javascript\">\r\n\t//<![CDATA[\r\n   function CheckController(formName, controller, controlled) {\r\n      var frm = document[formName];\r\n      var CheckedStatus = controller.checked;\r\n      if (frm[controlled]) {\r\n         if (frm[controlled].length) {\r\n            for (i = 0; i < frm[controlled].length; i++) {\r\n               frm[controlled][i].checked = CheckedStatus;\r\n            }\r\n         } else {\r\n            frm[controlled].checked = CheckedStatus;\r\n         }\r\n      }\r\n   }\r\n\t//]]>\r\n</script>\r\n</head>\r\n<body>";
if ($PageAction == "Generate") {
    $p = new Parameters();
    $ExcludeByPrefix = "ImageID";
    $p->DefineCollection($_GET, $ExcludeByPrefix, 0, 1);
    $p->DefineCollection($_POST, $ExcludeByPrefix, 0, 1);
Exemple #4
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once "Thumbnailer.class.php";
$params = json_decode(base64_decode($_REQUEST['p']), true);
if (isset($_REQUEST['v']) && $_REQUEST['v'] == 1) {
    var_dump($params);
    exit;
}
$file = $params['file'];
$fileDir = '/mine/Pictures';
if (isset($params['type']) && $params['type'] == "thumb") {
    $filePath = $fileDir . "/" . $file;
    $thumbnailer = new Thumbnailer($fileDir);
    if (!$thumbnailer->generateThumb($filePath)) {
        echo "Failed to generate thumbnail" . PHP_EOL;
        exit;
    }
    $fileDir .= "/thumbnails";
}
$filePath = $fileDir . "/" . $file;
if (file_exists($filePath)) {
    // Note: You should probably do some more checks
    // on the filetype, size, etc.
    $contents = file_get_contents($filePath);
    // Note: You should probably implement some kind
    // of check on filetype
    header('Content-type: image/jpeg');
    echo $contents;
} else {
Exemple #5
0
 private function writeText(&$im, $x1, $y1, $x2, $y2, $message)
 {
     if (self::$white === null) {
         self::$white = ImageColorAllocate($im, 255, 255, 255);
     }
     if (self::$black === null) {
         self::$black = ImageColorAllocate($im, 0, 0, 0);
     }
     imagefilledrectangle($im, $x1, $y1, $x2, $y2, self::$black);
     $box = imagettfbbox(self::$fontsize, 0, TN_FONT, $message);
     $width = $box[4] - $box[0];
     $height = $box[1] - $box[7];
     $left = $x1 + ($x2 - $x1) / 2.0 - $width / 2;
     $top = $y1 + ($y2 - $y1) / 2.0 + $height / 2;
     imagettftext($im, 9, 0, $left, $top, self::$white, TN_FONT, $message);
 }
 protected function process(ViewBag $viewbag)
 {
     $this->SetView("MovieSelector");
     $viewbag->Query = $search = Param('search') == '' ? '' : Param('search');
     if (Param('series') === null) {
         $series = isset($_COOKIE['__mc_series']) ? trim($_COOKIE['__mc_series']) : '';
         $skip_cutted = isset($_COOKIE['__mc_skip_cutted']) ? $_COOKIE['__mc_skip_cutted'] == 'J' : '';
     } else {
         $series = trim(Param('series'));
         $skip_cutted = Param('skip_cutted') == 'J';
     }
     $viewbag->SkipCutted = $skip_cutted;
     if (Param('submit')) {
         list($chanid, $starttime) = explode(".", Param('Movie'));
         $_SESSION['SelectedMovie'] = new SelectedMovie();
         $_SESSION['SelectedMovie']->chanid = $chanid;
         $_SESSION['SelectedMovie']->starttime = $starttime;
         unset($_SESSION['list']);
         Thumbnailer::CleanCache();
         $this->Redirect('?rand=' . rand(0, 10000000));
     }
     setCookie("__mc_skip_cutted", $skip_cutted ? 'J' : 'N');
     setCookie("__mc_series", $series);
     $q = new Query("select title, count(1) as cnt, sum(filesize) as size\n\t\t        from recorded r\n\t\t       where transcoded = 0\n\t\t         and deletepending = 0");
     if ($skip_cutted) {
         $q->Append("and not exists (select 1 from recordedmarkup m where m.chanid=r.chanid and m.starttime=r.starttime and m.type in (0,1))");
     }
     $q->Append("group by title order by size desc");
     $available_series = array();
     $viewbag->Series = array();
     foreach ($q->Execute() as $v) {
         $size = sprintf("%.1f", DoubleVal($v->size) / 1024.0 / 1024.0 / 1024.0);
         $c = new StdClass();
         $c->Title = $v->title;
         $c->Size = $size;
         $c->Recordings = $v->cnt;
         $c->Selected = $series == $c->Title;
         $viewbag->Series[] = $c;
     }
     $q = new Query("select *,\n\t\t             unix_timestamp(starttime) as unix\n\t\t        from recorded  r\n\t\t       where transcoded = 0\n\t\t         and deletepending = 0");
     if ($series) {
         $q->Append("and title = :series");
         $q->series = $series;
     }
     $words = preg_split('!\\s+!', $viewbag->Query);
     $row = 0;
     foreach ($words as $v) {
         $v = trim(chop($v));
         if ($v > '') {
             $row++;
             $w1 = '%' . strtr($v, array('%' => '\\%')) . '%';
             $q->Append("and concat(coalesce(title, ''), ' ', coalesce(subtitle, ''), ' ', coalesce(description, '')) like :word" . $row);
             $q->Set('word' . $row, $w1);
         }
     }
     if ($skip_cutted) {
         $q->Append(" and not exists (select 1 from recordedmarkup m where m.chanid=r.chanid and m.starttime=r.starttime and m.type in (0,1))");
     }
     $sort_by_size = Param('sort_by_size');
     if ($sort_by_size) {
         $q->Append(" order by filesize desc");
     } else {
         $q->Append("order by starttime desc");
     }
     $viewbag->Movies = array();
     foreach ($q->Execute() as $item) {
         $c = new StdClass();
         $c->Value = $item->chanid . '.' . $item->unix;
         $c->Title = $item->title;
         $c->Subtitle = $item->subtitle;
         $c->Size = sprintf("%.1f", DoubleVal($item->filesize / 1024.0 / 1024.0 / 1024.0));
         $c->Starttime = $item->starttime;
         $viewbag->Movies[] = $c;
     }
 }
Exemple #7
0
 public function getThumbnailer()
 {
     $thumbnailer = new Thumbnailer($this->chanid, $this->starttime, $this->findStream());
     $thumbnailer->setWidth(TN_WIDTH);
     return $thumbnailer;
 }
 /**
  * Set allowed mime types.
  *
  * @param array $allowed
  */
 public static function setAllowed($allowed)
 {
     self::$allowed = $allowed;
 }
Exemple #9
0
 /**
  * Get the filename of a resized image, generating it if required
  *
  * @param  Model   &$model
  * @param  string  $field
  * @param  string  $size
  * @return string
  */
 public static function get(&$model, $field = null, $size = null)
 {
     // Find default field, if it's not given
     $field = $field ?: Thumbnailer::config($model, 'default_field');
     if (!$field) {
         $fields = Thumbnailer::config($model, 'fields');
         if (count($fields) == 1) {
             $field = head(array_keys($fields));
         } else {
             throw new Exception("No thumbnail field given and no default defined.");
         }
     }
     // is this a thumbnailable field?
     if (!Thumbnailer::config($model, 'fields', $field)) {
         throw new Exception("Field {$field} is not thumbnailable.");
     }
     // get all sizes
     $sizes = Thumbnailer::config($model, 'sizes', $field);
     // Find default size, if it's not given
     $size = $size ?: Thumbnailer::config($model, 'default_size', $field);
     if (!$size) {
         if (count($sizes) == 1) {
             $size = head($sizes);
         } else {
             throw new Exception("No thumbnail size given for {$field} and no default defined.");
         }
     }
     // are we asking for the original?
     if ($size === 'original') {
         if (static::config($model, 'keep_original', $field)) {
             return static::generate($model, $field, 'original');
         }
         throw new Exception("Original image for {$filed} not kept.");
     }
     // are we asking for a size name instead of WxH dimensions?
     if (array_key_exists($size, $sizes)) {
         $size = $sizes[$size];
     }
     // does the requested size exist or can we generate it on the fly?
     if (!in_array($size, $sizes) && static::config($model, 'strict_sizes', $field)) {
         throw new Exception("Can not get {$size} thumbnail for {$field}: strict_sizes enabled.");
     }
     return static::generate($model, $field, $size);
 }
Exemple #10
0
    $thumbnailsDirectory = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/thumbs/' . claro_get_current_group_data('directory');
} elseif (claro_is_in_a_course() && claro_is_course_allowed()) {
    $documentRootDir = get_path('coursesRepositorySys') . claro_get_course_path() . '/document';
    $thumbnailsDirectory = get_path('coursesRepositorySys') . claro_get_course_path() . '/tmp/thumbs';
} else {
    header('HTTP/1.1 403 Forbidden');
    exit;
}
$image = array_key_exists('img', $_REQUEST) ? secure_file_path($_REQUEST['img']) : null;
if (is_null($image)) {
    header('HTTP/1.1 403 Forbidden');
    exit;
}
$imagePath = $documentRootDir . $image;
if (file_exists($imagePath)) {
    list($width, $height, $type, $attr) = getimagesize($imagePath);
    $thumbWidth = 75;
    $newHeight = round($height * $thumbWidth / $width);
    $thumbnailer = new Thumbnailer($thumbnailsDirectory, $documentRootDir);
    $thumbPath = $thumbnailer->getThumbnail($image, $newHeight, $thumbWidth);
    if (!$thumbPath) {
        $thumbPath = $imagePath;
    }
    // end session to avoid lock
    session_write_close();
    claro_send_file($thumbPath);
    exit;
} else {
    header('HTTP/1.1 404 Not Found');
    exit;
}