Skip to content

Instantly share code, notes, and snippets.

@brettsnippets
Created May 1, 2014 23:37
Show Gist options
  • Save brettsnippets/11464449 to your computer and use it in GitHub Desktop.
Save brettsnippets/11464449 to your computer and use it in GitHub Desktop.
Returns Screenshot from Vimeo and Youtube.
function video_image($url){
if(preg_match('/youtu\.be/i', $url) || preg_match('/youtube\.com\/watch/i', $url)){
preg_match('/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/', $url, $matches);
return "http://img.youtube.com/vi/".$matches[7]."/0.jpg";;
} else if(preg_match('/vimeo\.com/i', $url)){
preg_match('/\/\/(www\.)?vimeo.com\/(\d+)($|\/)/', $url, $matches);
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/".$matches[2].".php";));
return $hash[0]["thumbnail_large"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment