Created
January 22, 2014 08:45
-
-
Save bramus/8555450 to your computer and use it in GitHub Desktop.
Vimeo Thumbnail Script - Gets the poster frame for a Vimeo video id.
This file contains 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 | |
/** | |
* Vimeo Thumbnail Script - Gets the poster frame for a Vimeo video id. | |
* @author Bramus Van Damme <[email protected]> | |
* | |
* Example Request: vimeothumb.php?id=83936766 | |
*/ | |
// Perform a GET request to a given URL. | |
// Uses `allow_url_fopen` if supported, or curl as a fallback. | |
function get($url) { | |
if (ini_get('allow_url_fopen')) return file_get_contents($url); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
} | |
// Extract ID from the URL | |
$id = isset($_GET['id']) ? $_GET['id'] : 0; | |
// Request the image hash with Vimeo | |
if ($id > 0) $hash = unserialize(get('http://vimeo.com/api/v2/video/' . $id . '.php')); | |
// Thumbnail found | |
if ($hash && isset($hash[0]) && isset($hash[0]['thumbnail_large'])) { | |
header('Content-type: image/jpeg'); | |
echo get($hash[0]['thumbnail_large']); | |
} | |
// No thumbnail found: return a valid, but blank image | |
else { | |
header('Cache-Control: no-cache'); | |
header('Content-type: image/gif'); | |
header('Content-length: 43'); | |
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); | |
} | |
// EOF |
Thanks for the script - very useful. You could change the //Thumbnail found section to the edit below to get a 960px thumbnail (or change "_960" in the last line to whatever width you like up to 1280). Heights work too by adding "x480" for example, for a height of 480px.
// Thumbnail found
if ($hash && isset($hash[0]) && isset($hash[0]['thumbnail_large'])) {
header('Content-type: image/jpeg');
$thumb640 = ($hash[0]['thumbnail_large']);
echo get (str_replace("_640","_960",$thumb640));
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a script that just returns the path to the thumbnail was more what i searched, but i could get that very quickly out of here ;)