Created
May 27, 2016 03:15
-
-
Save darcyclarke/f369b91f5c060e81552e5bfdc40b6d53 to your computer and use it in GitHub Desktop.
Get the video thumbnail for a YouTube video from a URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/***********************************************/ | |
/* Get a Youtube or Vimeo video's Thumbnail from a URL | |
/* http://darcyclarke.me/articles/development/get-image-for-youtube-or-vimeo-videos-from-url/ | |
/* | |
/* Copyright 2016, Darcy Clarke | |
/* Do what you want license | |
/***********************************************/ | |
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(file_get_contents('http://vimeo.com/api/v2/video/'.substr($image_url['path'], 1).'.php')); | |
return $hash[0]['thumbnail_small']; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment