Skip to content

Instantly share code, notes, and snippets.

@spiffin
Forked from bramus/vimeothumb.php
Last active November 10, 2016 20:35
Show Gist options
  • Save spiffin/7222966c0cd5f5f36747 to your computer and use it in GitHub Desktop.
Save spiffin/7222966c0cd5f5f36747 to your computer and use it in GitHub Desktop.
forked from bramus/vimeothumb.php
<?php
/**
* Vimeo Thumbnail Script - Gets the poster frame for a Vimeo video id.
* @author Bramus Van Damme <bramus@bram.us>
*
* Example Request: vimeothumb.php?id=83936766
*
* Now for any width up to 1280 - and custom height too - see Thumbnail found section below
*/
// 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 - change "_960" below to your custom width - and add a height with "x480".
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));
}
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment