Skip to content

Instantly share code, notes, and snippets.

@ReekenX
Created March 19, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReekenX/9635646 to your computer and use it in GitHub Desktop.
Save ReekenX/9635646 to your computer and use it in GitHub Desktop.
Thumbnail from youtube
function video_image($url){
$image_url = parse_url($url);
if($image_url['host'] == 'www.youtube.com' ||
$image_url['host'] == 'youtube.com'){
$array = explode("&", $image_url['query']);
return "http://img.youtube.com/vi/".substr($array[0], 2)."/0.jpg";
}else if($image_url['host'] == 'www.youtu.be' ||
$image_url['host'] == 'youtu.be'){
$array = explode("/", $image_url['path']);
return "http://img.youtube.com/vi/".$array[1]."/0.jpg";
}else if($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"));
return $hash[0]["thumbnail_medium"];
}
}
<img src="<?php echo video_image('youtube URL'); ?>" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment