Skip to content

Instantly share code, notes, and snippets.

@anjan011
Created November 11, 2015 15:19
Show Gist options
  • Save anjan011/3b6d13a9f7a8642ecc4c to your computer and use it in GitHub Desktop.
Save anjan011/3b6d13a9f7a8642ecc4c to your computer and use it in GitHub Desktop.
php - get vimeo video thumbnail image url
<?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>';
@faidhim
Copy link

faidhim commented May 3, 2018

code does not work ! simply copy/paste and exec. returns nothing!!

@enovision
Copy link

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.

@tarbundiyahitesh21
Copy link

this is old solution, now it's get error, any new solution is available ?

@ThatGuySam
Copy link

ThatGuySam commented Aug 27, 2020

@tarbundiyahitesh21

this is old solution, now it's get error, any new solution is available ?

<img src="https://vumbnail.com/358629078.jpg" />

@saraclima
Copy link

@tarbundiyahitesh21

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