Skip to content

Instantly share code, notes, and snippets.

@bagerathan
Created September 10, 2020 11:21
Show Gist options
  • Save bagerathan/3ba5af71c24ff7b4f89ea7443ffa413b to your computer and use it in GitHub Desktop.
Save bagerathan/3ba5af71c24ff7b4f89ea7443ffa413b to your computer and use it in GitHub Desktop.
Get video thumbnails
//return thumbnail for youtube and vimeo
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.vimeo.com' || $image_url['host'] == 'vimeo.com'){
$hash = unserialize(curl_get_file_contents('http://vimeo.com/api/v2/video/'.substr($image_url['path'], 1).'.php'));
return $hash[0]['thumbnail_small'];
}
}
function curl_get_file_contents($URL){
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment