Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaclyntan/c80537968cde7bf429d541bfc82026f4 to your computer and use it in GitHub Desktop.
Save jaclyntan/c80537968cde7bf429d541bfc82026f4 to your computer and use it in GitHub Desktop.
function get_video_thumbnail( $src ) {
$url_pieces = explode('/', $src);
if ( $url_pieces[2] == 'vimeo.com' ) { // If Vimeo
$id = $url_pieces[3];
$hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/' . $id . '.php'));
$thumbnail = $hash[0]['thumbnail_large'];
} elseif ( $url_pieces[2] == 'www.youtube.com' ) { // If Youtube
$extract_id = explode('?', $url_pieces[3]);
$watchid = $extract_id[1];
$id = substr($watchid, 2);
$thumbnail = 'http://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
}
return $thumbnail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment