Created
November 11, 2015 15:19
-
-
Save anjan011/3b6d13a9f7a8642ecc4c to your computer and use it in GitHub Desktop.
php - get vimeo video thumbnail image 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 | |
/** | |
* 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>'; | |
You should make this:
"http://vimeo.com/api/v2/video/$id.php"
a little more flexible. This won't work when the requesting site is SSL (https). When modified it works like a charm. Thank you.
this is old solution, now it's get error, any new solution is available ?
this is old solution, now it's get error, any new solution is available ?
<img src="https://vumbnail.com/358629078.jpg" />
this is old solution, now it's get error, any new solution is available ?
<img src="https://vumbnail.com/358629078.jpg" />
this worked for me
https://gist.github.com/bacoords/77ee4d13dfa76db03981cb4eb0df0c6f
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code does not work ! simply copy/paste and exec. returns nothing!!