예제 #1
0
 public function Run()
 {
     require_once 'Oops/Kcaptcha/Image.php';
     $captcha = new Oops_Kcaptcha_Image();
     $img = $captcha->action();
     require_once 'Oops/File/Temporary.php';
     $file = new Oops_File_Temporary();
     if (function_exists("imagejpeg")) {
         $this->_response->setHeader("Content-type", "image/jpeg");
         imagejpeg($img, $file->filename, $captcha->config->jpeg_quality);
     } elseif (function_exists("imagegif")) {
         $this->_response->setHeader("Content-type", "image/gif");
         imagegif($img, $file->filename);
     } elseif (function_exists("imagepng")) {
         $this->_response->setHeader("Content-type", "image/png");
         imagepng($img, $file->filename);
     }
     $this->_response->setBody($file->getContents());
     $this->_response->setCode(200);
 }
예제 #2
0
 /**
  * @return Oops_File_Temporary
  */
 public function getPreview()
 {
     if (!$this->isVideo()) {
         require_once 'Oops/Video/Exception.php';
         throw new Oops_Video_Exception("Not a video file");
     }
     /**
      * Prepare tmp dir
      */
     require_once 'Oops/File/Temporary.php';
     $tmp = new Oops_File_Temporary(self::$_config->tmpdir);
     $tmp->toDir();
     $outdir = $tmp->filename;
     if (strpos($outdir, ':') !== false || strpos($outdir, ' ') !== false) {
         //trying to prevent windows-speciefic path symbols
         if (strpos($outdir, realpath('.') . DIRECTORY_SEPARATOR) === 0) {
             // Temp dir path is inside working dir, use relative path
             $outdir = str_replace(realpath('.') . DIRECTORY_SEPARATOR, '', $outdir);
         } elseif (strpos($outdir, ":") === 1 && substr($outdir, 0, 2) == substr(realpath('.'), 0, 2)) {
             // Temp dir located on the same drive as working dir, replace X:\ with / and replace directory separator to unix style
             $outdir = substr(str_replace(DIRECTORY_SEPARATOR, '/', $outdir), 2);
         } elseif (strpos($outdir, ":")) {
             require_once 'Oops/Video/Exception.php';
             throw new Oops_Video_Exception("Can not eliminate semicolon sign in temp dir path");
         }
     }
     if (strpos($outdir, ' ') !== false) {
         $outdir = '"' . $outdir . '"';
     }
     $execString = "mplayer";
     self::_initConfig();
     $config = clone self::$_config->preview;
     $config->mergeConfig(new Oops_Config(array("vo" => "jpeg:outdir={$outdir}")));
     if (isset($this->_videoStats['LENGTH'])) {
         $len = floor($this->_videoStats['LENGTH']);
         $ss = strtotime($config->ss . " +0000", 0);
         if ($len < $ss) {
             $config->mergeConfig(new Oops_Config(array("ss" => gmdate("H:i:s", round($len / 2)))));
         }
     }
     foreach ($config as $k => $v) {
         $execString .= " -{$k} {$v}";
     }
     $execString .= " {$this->_filename}";
     exec($execString);
     $files = glob($tmp->filename . DIRECTORY_SEPARATOR . "/*.*");
     if (!is_array($files) || !count($files)) {
         require_once 'Oops/Video/Exception.php';
         throw new Oops_Video_Exception("No frames extracted with {$execString}");
     }
     $jpegContents = file_get_contents(end($files));
     $result = new Oops_File_Temporary();
     $result->putContents($jpegContents);
     $result->type = 'image/jpeg';
     return $result;
 }