get Video image by URL – function getVideoImage($url)
Omschrijving
function getVideoImage($url) {
$thumbnail_uri = '';
// Get background image for YouTube or Vimeo video
if (strpos($url, 'youtube') !== false) {
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$id = $my_array_of_vars['v'];
$thumbnail_uri = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg';
}
if (strpos($url, 'youtu.be') !== false) {
$id = substr($url, strrpos($url, '/') + 1);
$thumbnail_uri = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg';
}
if (strpos($url, 'vimeo') !== false) {
$data = json_decode(file_get_contents('https://vimeo.com/api/oembed.json?url=' . $url));
if(!$data) return false;
$thumbnail = $data->thumbnail_url;
// Remove thumbnail size, add jpg extension
$thumbnail_uri = strstr($thumbnail, '_', true) . '.jpg';
}
return $thumbnail_uri;
}Snippet
| Field | Value |
|---|---|
| Snippet Status | Done |
| Snippet Description | Haalt de image op vanaf de streaming dienst. |
| Snippet Type Code | PHP |
| Snippet URL | |
| Snippet Content | function getVideoImage($url) { $thumbnail_uri = ''; // Get background image for YouTube or Vimeo video if (strpos($url, 'youtube') !== false) { parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars ); $id = $my_array_of_vars['v']; $thumbnail_uri = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg'; } if (strpos($url, 'youtu.be') !== false) { $id = substr($url, strrpos($url, '/') + 1); $thumbnail_uri = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg'; } if (strpos($url, 'vimeo') !== false) { $data = json_decode(file_get_contents('https://vimeo.com/api/oembed.json?url=' . $url)); if(!$data) return false; $thumbnail = $data->thumbnail_url; // Remove thumbnail size, add jpg extension $thumbnail_uri = strstr($thumbnail, '_', true) . '.jpg'; } return $thumbnail_uri; } |
| Snippet Content CSS | |
| Snippet Content HTML | |
| Snippet Content JS | |
| Snippet Content PHP | function getVideoImage($url) { $thumbnail_uri = ''; // Get background image for YouTube or Vimeo video if (strpos($url, 'youtube') !== false) { parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars ); $id = $my_array_of_vars['v']; $thumbnail_uri = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg'; } if (strpos($url, 'youtu.be') !== false) { $id = substr($url, strrpos($url, '/') + 1); $thumbnail_uri = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg'; } if (strpos($url, 'vimeo') !== false) { $data = json_decode(file_get_contents('https://vimeo.com/api/oembed.json?url=' . $url)); if(!$data) return false; $thumbnail = $data->thumbnail_url; // Remove thumbnail size, add jpg extension $thumbnail_uri = strstr($thumbnail, '_', true) . '.jpg'; } return $thumbnail_uri; } |
| Particle Snippet in Software | 1 |
| Particle Snippet in Boilerplate | 0 |
Relations
| Item | Type |
|---|
Pointing items
| Item | Type | Category | Tags |
|---|
| Categorie | Snippet |
| Tags | embed-image, Function, Helper, helpers.php, video-image |
| URL | |
| Type | Snippet |
| Time | |
| Price |