Tag Archives: Youtube Thumbnail

How to get image from youtube and vimeo embedded url?

Youtube And Vimeo Image

This tutorial for gettting the image from youtube and vimeo embedded url using the php code without any 3rd party tools. you can just enter the embedded url in below code and get HD Image from this two plateform

Step 1)

just put this code in your php file where you want to get the youtube and vimeo embedded url image in high resolution.

$url2 = "Your youtube and vimeo embedded url here";
$parsed     = parse_url($url2);
$hostname   = $parsed['host']; 
$path       = $parsed['path']; 
if(!empty($hostname)){
  if($hostname=='www.youtube.com' || $hostname=='youtube.com'){
	preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url2, $match);
	$youtube_id = $match[1];
        $videoID = substr($youtube_id,0,11);
        $video_image_src = "https://i.ytimg.com/vi/".$videoID."/maxresdefault.jpg";
	$video_image_href = "https://www.youtube.com/embed/".$videoID;
}else if($hostname=='player.vimeo.com'){
	preg_match("/vimeo\.com\/(\w+\s*\/?)*([0-9]+)*$/i", $url2, $output_array);
	$vimdeoIDInt = intval($output_array[1]);
	$vimeo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vimdeoIDInt.php"));
	$small = $vimeo[0]['thumbnail_small'];
	$medium = $vimeo[0]['thumbnail_medium'];
	$large = $vimeo[0]['thumbnail_large'];
        $video_image_src = $large;
	$video_image_href = "https://player.vimeo.com/video/".$vimdeoIDInt; 
 }
echo $video_image_href;
}