유튜브, 비메오 영상 가져오기 이미지 가져오기
페이지 정보
본문
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가;
//아이디로 이미지 src 가져오기
function get_youtube_image($video_url, $thumb_type="", $thumb_width="") {
$video = array();
$query = array();
$video_url = trim(strip_tags($video_url));
list($url, $opt) = explode("|", $video_url);
$url = trim($url);
if($url) {
if(!preg_match('/(http|https)\:\/\//i', $url)) {
$url = 'http:'.$url;
}
} else {
return;
}
$video['video'] = str_replace(array(" ", " "), array("", ""), $url);
$video['video_url'] = str_replace(array(" ", "&", " "), array("", "&", ""), $url);
$info = @parse_url($video['video_url']);
if($info['host'] == "youtu.be") { //유튜브
$video['type'] = 'youtube';
$video['vid'] = trim(str_replace("/","", trim($info['path'])));
$video['vid'] = substr($video['vid'], 0, 11);
} else if($info['host'] == "www.youtube.com" || $info['host'] == "m.youtube.com") { //유튜브
$video['type'] = 'youtube';
if(preg_match('/\/embed\//i', $video['video_url'])) {
list($youtube_url, $youtube_opt) = explode("/embed/", $video['video_url']);
$vids = explode("?", $youtube_opt);
$video['vid'] = $vids[0];
} else {
$vids = explode("?v=", $video['video_url']);
$video['vid'] = substr($vids[1], 0, 11);
}
} else if($info['host'] == "vimeo.com") { //vimeo
$video['type'] = 'vimeo';
$video['vid'] = trim(str_replace("/","", trim($info['path'])));
$video['vid'] = substr($video['vid'], 0, 9);
$vimeo_url = "http://vimeo.com/api/v2/video/".$video['vid'].".json";
$vimeo_curl = curl_init ();
curl_setopt ($vimeo_curl, CURLOPT_URL, $vimeo_url);
curl_setopt ($vimeo_curl, CURLOPT_POST, 0);
curl_setopt ($vimeo_curl, CURLOPT_RETURNTRANSFER, 1);
$vimeo_response = curl_exec ($vimeo_curl);
$vimeo_returns = json_decode($vimeo_response);
}
if($video['vid']) {
switch($thumb_type){
/*case '0' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/0.jpg';
break;*/
case '1' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/1.jpg';
break;
case '2' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/2.jpg';
break;
case '3' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/3.jpg';
break;
case 'hq' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/hqdefault.jpg';
break;
case 'mq' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/mqdefault.jpg';
break;
case 'sd' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/sddefault.jpg';
break;
case 'maxres' :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/maxresdefault.jpg';
break;
case 'thumbnail_small' :
$videoimg = $vimeo_returns[0]->thumbnail_small;
break;
case 'thumbnail_medium' :
$videoimg = $vimeo_returns[0]->videoimg;
break;
case 'thumbnail_large' :
$videoimg = $vimeo_returns[0]->videoimg;
break;
default :
$videoimg = '//img.youtube.com/vi/'.$video['vid'].'/default.jpg';
}
if($thumb_type) {
echo '<a href="'.$video_url.'" target="_blank" class="lt_thumb"><img src="'.$videoimg.'" alt="" class="lt_img" width="'.$thumb_width.'"></a>';
} else {
if($video['type'] == "youtube") { //youtube
echo '<div class="video-wrap"><iframe width="1280" height="720" src="https://www.youtube.com/embed/'.$video['vid'].'" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>';
} else if($video['type'] == "vimeo") { //vimeo
echo '<div class="video-wrap"><iframe width="1280" height="720" src="https://player.vimeo.com/video/'.$video['vid'].'" title="vimeo-player" frameborder="0" allowfullscreen></iframe></div>';
}
}
}
}
?>
.video-wrap {position:relative; padding-bottom:56.25%; padding-top:30px; height:0; overflow:hidden;}
.video-wrap iframe,
.video-wrap object,
.video-wrap embed {position:absolute; top:0; left:0; width:100%; height:100%;}
댓글목록
등록된 댓글이 없습니다.