Ejemplo n.º 1
0
 function create($name, $param = array())
 {
     global $m;
     $width = @(int) $param['width'];
     $height = @(int) $param['height'];
     $prefix = @$param['prefix'];
     $max_width = 0;
     $max_height = 0;
     $desc = array(2 => array("pipe", "w"));
     $process = @proc_open('ffmpeg -i "' . $this->image_path . '/' . $name . '"', $desc, $pipes);
     if (is_resource($process)) {
         $info = stream_get_contents($pipes[2]);
         preg_match('/\\,\\ (\\d*)x(\\d*)(\\,|\\ )/si', $info, $res);
         $max_width = @(int) $res[1];
         $max_height = @(int) $res[2];
         fclose($pipes[2]);
         proc_close($process);
     }
     if (@$param['time']) {
         $name = explode('.', $name);
         $ext = array_pop($name);
         $name = implode('.', $name);
         @exec('ffmpeg -i "' . $this->image_path . '/' . $name . '.' . $ext . '" -an -ss ' . (int) $param['time'] . ' -r 1 -vframes 1 ' . ($max_width && $max_height ? '-s ' . $max_width . 'x' . $max_height : '') . ' -y -f mjpeg "' . $this->path . '/' . $prefix . $name . '.jpg"');
         $preview = new Zkernel_Image_Preview($this->path, $this->path);
         $param['prefix'] = '';
         $preview->create($prefix . $name . '.jpg', $param);
         copy($this->path . '/' . $prefix . $name . '.jpg', $this->path . '/' . $prefix . $name . '.' . $ext);
         unlink($this->path . '/' . $prefix . $name . '.jpg');
         @chmod($this->path . '/' . $prefix . $name . '.' . $ext, 0777);
     } else {
         if (!$width || !$height) {
             return false;
         }
         if (!$max_width || !$max_height) {
             return false;
         }
         if ($width > $max_width) {
             $width = $max_width;
         }
         if ($height > $max_height) {
             $height = $max_height;
         }
         if ($width / 2 != floor($width / 2)) {
             $width++;
         }
         if ($height / 2 != floor($height / 2)) {
             $height++;
         }
         @exec('ffmpeg -i "' . $this->image_path . '/' . $name . '" ' . ($width && $height ? '-s ' . $width . 'x' . $height : '') . ' -qscale 4 -y -f flv -acodec libmp3lame -ac 1 -ar 44100 -ab 96k "' . $this->path . '/' . $prefix . $name . '"');
         if (!file_exists($this->path . '/' . $prefix . $name)) {
             @exec('ffmpeg -i "' . $this->image_path . '/' . $name . '" ' . ($width && $height ? '-s ' . $width . 'x' . $height : '') . ' -qscale 4 -y -f flv -ac 1 -ar 44100 -ab 96k "' . $this->path . '/' . $prefix . $name . '"');
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function preview($dir = null, $name, $param = array())
 {
     if (!$dir || !$name) {
         return @$param['default'];
     }
     $prefix = $param['prefix'] = @$param['prefix'] ? $param['prefix'] . '_' : '';
     $ext = strrpos($name, '.');
     $ext = $ext === false ? '' : @substr($name, $ext + 1);
     $ctype = 'image';
     if ($ext == 'flv' || $ext == 'avi' || $ext == '3gp' || $ext == 'wmv') {
         $ctype = 'video';
     }
     $modified_o = @filemtime(PUBLIC_PATH . '/upload/' . $dir . '/' . $name);
     if (!$modified_o) {
         return @$param['default'];
     }
     $png_name = @$param['corner'] && $ctype == 'image' ? preg_replace('/\\.(.+)$/', '.png', $name) : '';
     $param['new_name'] = $png_name;
     $cp = defined('CACHE_DIR') ? CACHE_DIR : 'pc';
     $dir_dest = @$param['cache_dir_folder'] ? $param['cache_dir_folder'] : $dir;
     $modified = @filemtime(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . ($png_name ? $png_name : $name));
     if ($modified < $modified_o) {
         if (!@file_exists(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest)) {
             mkdir(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest, 0777, true);
         }
         if ($ctype == 'image') {
             $preview = new Zkernel_Image_Preview(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest, PUBLIC_PATH . '/upload/' . $dir);
             $preview->create($name, $param);
         } else {
             if ($ctype == 'video') {
                 $preview = new Zkernel_Video_Preview(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest, PUBLIC_PATH . '/upload/' . $dir);
                 $preview->create($name, $param);
             }
         }
         @chmod(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . $name, 0777);
         @clearstatcache();
         $modified = @filemtime(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . $name);
     }
     $ret = $modified || @file_exists(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . ($png_name ? $png_name : $name)) ? '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . ($png_name ? $png_name : $name) . '?' . $modified : @$param['default'];
     return Zkernel_Common::gen_static_url($ret);
 }