Ejemplo n.º 1
0
 /**
  * Extract a frame from a remote video
  *
  * @param string	$video	the video
  * @param string	$image	the frame
  * @param array		$sizes	width and height to scale	
  * @return mixed
  */
 public static function remote_video_frame($video, $image, $sizes = array())
 {
     $frame = '';
     $image_url = parse_url($video);
     if ($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com') {
         $array = explode("&", $image_url['query']);
         $frame = 'http://img.youtube.com/vi/' . substr($array[0], 2) . '/0.jpg';
     } elseif ($image_url['host'] == 'youtu.be') {
         $path = explode('/', $image_url['path']);
         $frame = 'http://i.ytimg.com/vi/' . $path[1] . '/0.jpg';
     } elseif ($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com') {
         $hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/' . substr($image_url['path'], 1) . '.php'));
         $frame = $hash[0]['thumbnail_large'];
     }
     if (!empty($frame)) {
         // we can extract a frame
         $ipath = APATH . 'files/filemanager/img/';
         // set the new name
         $final_name = self::get_final_name($ipath, $image);
         // copy remote file
         $chk = copy($frame, $ipath . $final_name);
         if ($chk && file_exists($ipath . $final_name)) {
             chmod($ipath . $final_name, 0777);
             $check = X4Files_helper::create_fit($ipath . $final_name, $ipath . $final_name, $sizes, true);
             return $final_name;
         }
         return '';
     }
 }