示例#1
0
 protected function _output($filename, $mime)
 {
     $output = new QView_Output($filename, $mime);
     $output->addFile(dirname(__FILE__) . "/../..//static/{$filename}");
     $output->enableClientCache(true);
     return $output;
 }
示例#2
0
 protected function _output($filename, $mime)
 {
     $output = new QView_Output($filename, $mime);
     $output->addFile($this->app()->ROOT_DIR() . "/static/{$filename}");
     $output->enableClientCache(true);
     return $output;
 }
示例#3
0
 /**
  * 生成验证码图像,返回 QView_Output 对象
  *
  * $param string $code
  *
  * @return QView_Output
  */
 function generateImage($code)
 {
     // 确定要使用的字体
     if (isset(self::$_font_list[$this->_options['font']])) {
         $font = Q_DIR . '/_resources/' . self::$_font_list[$this->_options['font']];
     } else {
         $font = $this->_options['font'];
     }
     // 确定图像的宽度和高度
     $border = $this->_options['border'];
     $float_pixel = intval($this->_options['float_pixel']);
     $padding = intval($this->_options['padding']);
     $width = intval($this->_options['width']) + $padding * 2 + $border * 2 + 1;
     $width *= 2;
     $height = intval($this->_options['height']) + $padding * 2 + $border * 2 + 1 + $float_pixel;
     // 创建图像
     $img = imagecreatetruecolor($width, $height);
     // 绘制背景
     list($r, $g, $b) = Helper_ImgCode::hex2rgb($this->_options['bgcolor']);
     imagefilledrectangle($img, $border, $border, $width - $border - 1, $height - $border - 1, imagecolorallocate($img, $r, $g, $b));
     // 绘制文字
     $max_angle = intval($this->_options['max_angle']);
     $x = $padding + $padding + $border;
     $bottom = $height - $padding + $border - $float_pixel * 2;
     $font_space = $this->_options['font_space'];
     $color_arr = Helper_ImgCode::hex2rgb($this->_options['color']);
     $arr = array();
     $font_size = $this->_options['font_size'];
     $min_r = $r + 50;
     $min_g = $g + 50;
     $min_b = $b + 50;
     for ($i = 0, $max = strlen($code); $i < $max; $i++) {
         $arr[$i]['font_size'] = mt_rand(50, 150) / 100 * $font_size;
         $arr[$i]['angle'] = rand(0, $max_angle) - $max_angle / 2;
         list($r, $g, $b) = $color_arr;
         $r = ($r + rand(0, 2550)) % (255 - $min_r) + $min_r;
         $g = ($g + rand(0, 2550)) % (255 - $min_g) + $min_g;
         $b = ($b + rand(0, 2550)) % (255 - $min_b) + $min_b;
         $arr[$i]['color'] = imagecolorallocate($img, $r, $g, $b);
     }
     for ($i = 0; $i < $max; $i++) {
         $x += $font_space;
         $y = $bottom;
         list(, , $x) = imagettftext($img, $arr[$i]['font_size'], $arr[$i]['angle'], $x, $y, $arr[$i]['color'], $font, $code[$i]);
         imagecolordeallocate($img, $arr[$i]['color']);
     }
     $new_width = intval($this->_options['width']) + $padding * 2 + $border * 2 + 1;
     $img_output = imagecreatetruecolor($new_width, $height);
     imagecopyresampled($img_output, $img, 0, 0, 0, 0, $new_width, $height, $x + $padding + $border, $height);
     imagedestroy($img);
     // 绘制边框
     if ($border) {
         list($r, $g, $b) = Helper_ImgCode::hex2rgb($this->_options['bdcolor']);
         imagerectangle($img_output, 0, 0, $width, $height, imagecolorallocate($img_output, $r, $g, $b));
     }
     $filename = 'imgcode-' . mt_rand();
     ob_start();
     // 输出图像
     switch (strtolower($this->_options['image_type'])) {
         case 'png':
             $filename .= '.png';
             $mime = image_type_to_mime_type(IMAGETYPE_PNG);
             imagepng($img_output);
             break;
         case 'gif':
             $filename .= '.gif';
             $mime = image_type_to_mime_type(IMAGETYPE_GIF);
             imagegif($img_output);
             break;
         case 'jpg':
         default:
             $filename .= '.jpg';
             $mime = image_type_to_mime_type(IMAGETYPE_JPEG);
             imagejpeg($img_output);
     }
     imagedestroy($img_output);
     $output = new QView_Output($filename, $mime, ob_get_clean());
     $output->enableClientCache(false);
     return $output;
 }
示例#4
0
 static function getPreviewFileStream($id)
 {
     $file = Files::find()->getById($id);
     if ($file->isNewRecord()) {
         return;
     }
     $fileName = rtrim($file->path, '/\\') . DS . $file->name . '.' . $file->ext;
     if ($file->type == 1 || $file->type == 2) {
         $fileNamePreview = rtrim($file->path, '/\\') . DS . $file->name . '-preview.flv';
         $lock = $fileNamePreview . '.lock';
         while (true) {
             if (!file_exists($lock)) {
                 break;
             }
         }
         if (!file_exists($fileNamePreview) || !@filesize($fileNamePreview)) {
             $lock = $fileNamePreview . '.lock';
             if (!file_exists($lock)) {
                 @ignore_user_abort(1);
                 @set_time_limit(0);
                 @touch($lock);
                 $ffmpegPath = Q::ini('appini/catalog/ffmpegPath');
                 $ffmpegParameter = Q::ini('appini/catalog/ffmpegParameter');
                 //$command = "$ffmpegPath -i \"$fileName\" -y -ab 56 -ar 22050 -r 15 -b 500 -s 320x240 \"$fileNamePreview\"";
                 //$command = "$ffmpegPath -i \"$fileName\" -y -ab 56 -ar 22050 -r 15 -s 320x240 \"$fileNamePreview\"";
                 $command = "{$ffmpegPath} -i \"{$fileName}\" {$ffmpegParameter} \"{$fileNamePreview}\"";
                 //$command .= "&& $ffmpegPath -i \"$fileName\" -y -f image2 -ss 8 -t 0.011 -s 320x240 \"$fileNamePreview.jpg\"";
                 @exec($command);
                 @unlink($lock);
             }
         }
         $output = new QView_Output($file->title . '.' . $file->ext, 'video/x-flv');
         $output->addFile($fileNamePreview);
         return $output;
     } else {
         if ($file->type == 4) {
             if ($file->ext == 'txt') {
                 $handle = @fopen($fileName, 'r');
                 $data = @fread($handle, @filesize($fileName));
                 @fclose($handle);
                 return Helper_Util::encoding($data, 'utf-8');
             } else {
                 return '无法预览非文本文件(*.txt)格式';
             }
         } else {
             $output = new QView_Output($file->title);
             $output->addFile($fileName);
             if ($file->ext == 'jpg' || $file->ext == 'jpeg') {
                 $output->setMimeType('image/jpeg');
             }
             return $output;
         }
     }
 }