Skip to content

Instantly share code, notes, and snippets.

@codemaker38
Created April 10, 2012 04:47
Show Gist options
  • Save codemaker38/2348368 to your computer and use it in GitHub Desktop.
Save codemaker38/2348368 to your computer and use it in GitHub Desktop.
Video: Thumbnail for Youtube and Vimeo
<?php
# get video info
$video_photo = base_url() .'images/profiles/no-thumb.jpg';
preg_match('/http:\/\/vimeo.com\/(\d+)$/', $video['link'], $vimeo);
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video['link'], $youtube);
if(count($vimeo) > 0) {
$vimeo_id = $vimeo[1];
$vimeo_photo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vimeo_id.php"));
$video_photo = $vimeo_photo[0]['thumbnail_small'];
}
if(count($youtube) > 0) {
$video_id = $youtube[1];
$video_photo = 'http://img.youtube.com/vi/' . $video_id . '/' . rand(1, 3) . '.jpg';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment