Forked from anjan011/php-vimeo-video-thumbnail-url.php
Created
October 17, 2017 05:06
-
-
Save roryheaney/48bbe8ed3568116064c54a39f685a0fc to your computer and use it in GitHub Desktop.
php - get vimeo video thumbnail image url
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 | |
/** | |
* Gets the thumbnail url for a vimeo video using the video id. This only works for public videos. | |
* | |
* @param string $id The video id. | |
* @param string $thumbType Thumbnail image size. supported sizes: small, medium (default) and large. | |
* | |
* @return string|bool | |
*/ | |
function getVimeoVideoThumbnailByVideoId( $id = '', $thumbType = 'medium' ) { | |
$id = trim( $id ); | |
if ( $id == '' ) { | |
return FALSE; | |
} | |
$apiData = unserialize( file_get_contents( "http://vimeo.com/api/v2/video/$id.php" ) ); | |
if ( is_array( $apiData ) && count( $apiData ) > 0 ) { | |
$videoInfo = $apiData[ 0 ]; | |
switch ( $thumbType ) { | |
case 'small': | |
return $videoInfo[ 'thumbnail_small' ]; | |
break; | |
case 'large': | |
return $videoInfo[ 'thumbnail_large' ]; | |
break; | |
case 'medium': | |
return $videoInfo[ 'thumbnail_medium' ]; | |
default: | |
break; | |
} | |
} | |
return FALSE; | |
} | |
// Example usage ... | |
$videoId = '145154247'; | |
echo '<img src="'.getVimeoVideoThumbnailByVideoId($videoId,'small').'" title="Small Thumbnail">'.'<br>'; | |
echo '<img src="'.getVimeoVideoThumbnailByVideoId($videoId,'medium').'" title="Medium Thumbnail">'.'<br>'; | |
echo '<img src="'.getVimeoVideoThumbnailByVideoId($videoId,'large').'" title="Large Thumbnail">'.'<br>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment