유튜브, 비메오 영상 가져오기 이미지 가져오기 > 팁앤테크

본문 바로가기
사이트 내 전체검색

팁앤테크

유튜브, 비메오 영상 가져오기 이미지 가져오기

페이지 정보

본문

<?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%;}

 

 

 

추천0

댓글목록

등록된 댓글이 없습니다.

Total 825건 33 페이지
  • RSS
팁앤테크 목록
번호 제목 글쓴이 조회 추천 날짜
25 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2872 0 10-31
24 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2817 0 02-26
23 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2803 0 03-12
22 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2750 0 02-27
21 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2500 0 03-29
20 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2479 0 03-10
19 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2476 0 03-03
18 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2430 0 07-08
17 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2411 0 06-03
16 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2399 0 07-08
15 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2369 0 03-26
열람중 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2334 0 04-06
13 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2193 0 04-16
12 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2171 0 12-24
11 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2139 0 02-21
10 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2124 0 10-17
9 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2078 0 08-03
8 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2049 0 10-02
7 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2028 0 12-04
6 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2014 0 12-31
5 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1993 0 08-04
4 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1907 0 06-09
3 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1688 0 08-04
2 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1250 0 07-10
1 제로쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1036 0 11-02

검색

회원로그인

회원가입

사이트 정보

株式会社YHPLUS / 대표 : ZERO
〒140-0011 東京都品川区東大井2-5-9-203
050-5539-7787
오픈카카오톡 (YHPLUS) :
https://open.kakao.com/o/slfDj15d

접속자집계

오늘
1,078
어제
5,081
최대
7,259
전체
1,280,243
Copyright (c) 株式会社YHPLUS. All rights reserved.