Getting The Vimeo Thumbnail

It’s easy to get the YouTube thumbnail for a video, but Vimeo is a little bit harder. I’ve run into a few situations where I was using PHP and needed to get the thumbnail pulled. Each time I have to go back and reconstruct code that I’ve found from the web. I’ve also run into fopen errors, so I rebuilt the code to use cURL and wrapped it in a handy function. This code will get you any data you need from Vimeo:


function getVimeoInfo($id, $info = 'thumbnail_medium') {
	if (!function_exists('curl_init')) die('CURL is not installed!');
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_TIMEOUT, 10);
	$output = unserialize(curl_exec($ch));
	$output = $output[0][$info];
	curl_close($ch);
	return $output;
}

To use this function, simply call it with the info you are looking for. By default, the function will return the medium thumbnail.


echo getVimeoInfo(644453);
echo getVimeoInfo(644453,"thumbnail_small");

Here are the values that you can get:

  • id
  • title
  • description
  • url
  • upload_date
  • mobile_url
  • thumbnail_small
  • thumbnail_medium
  • thumbnail_large
  • user_name
  • user_url
  • user_portrait_small
  • user_portrait_medium
  • user_portrait_large
  • user_portrait_huge
  • stats_number_of_likes
  • stats_number_of_plays
  • stats_number_of_comments
  • duration
  • width
  • height
  • tags

UPDATE: D.O. sent over an alternate function to use if you have multiple pieces of data you need to get from each video (so that you don't have to keep running the function over and over again).


function getVimeoInfo($id) {
                if (!function_exists('curl_init')) die('CURL is not installed!');
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                $output = unserialize(curl_exec($ch));
                $output = $output[0];
                curl_close($ch);
                return $output;
}

$VideoInfo = getVimeoInfo($id);
$thumb = $VideoInfo['thumbnail_medium'];
$tags = $VideoInfo ['tags'];
$longdesc = $VideoInfo ['description'];

24 Responses to “Getting The Vimeo Thumbnail”

  1. Perfect.

    Something changed on either my host or Vimeo’s API and the old method (file_get_contents) I was using to grab thumbnails stopped working.

  2. Thanks!

    I’m trying to use this in a situation where I have the Vimeo video ID # stored as a string in a variable. When I put the variable as the id argument in the getVimeoInfo function call, it returns a php error. I suspect it’s because it’s the wrong type? How can I fix this?

  3. Hey I had this method working for a week, and then went back to the site and it was broken.

    Any thoughts?
    http://whatgodsdoing.net

  4. Sorry Sam, I just saw your message. This is a clean way to convert to integer:

    settype($foo, “integer”);

    http://php.net/manual/en/function.settype.php

  5. Thank you, really appreciate you taking the time to post this, saved me hours of work!

  6. I modified your function so it returns all the data as an associative array. This way you don’t have to execute the function for every piece of data you want from vimeo.

    function getVimeoInfo($id) {
    if (!function_exists(‘curl_init’)) die(‘CURL is not installed!’);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, “http://vimeo.com/api/v2/video/$id.php”);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = unserialize(curl_exec($ch));
    $output = $output[0];
    curl_close($ch);
    return $output;
    }

    Example of use:

    <img src="” width=”210″ alt=”” longdesc=”” />

  7. Sorry, my example couldn’t be displayed because this site stripped code from it.

  8. Hi.

    Is there a way to automatically set thumbails if there is a post that includes a vimeo video embed code? I use the iframes from vimeo to be able to show the videos on mobile devices as well as on pc´s.
    I´m not very familiar with coding so please be patient with me. ;)
    Perhaps there´s even a wp-plugin that makes this job. I found one for youtube, but couldn´t find one for vimeo.

    Cheers, Chris

  9. Hi Chris, I think the best solution would be to retrofit the youtube plugin to work with the vimeo code, but that would take some php knowledge and some elbow grease. I don’t know of any pre-packaged solution.

  10. Do you know whether there is any limit on the number of calls to Vimeo API? Thanks.

  11. @Tri I’m not sure. I don’t see any indication that there is a limit, but remember that this process is not particularly speedy so if you have tons of calls to do on one page you might be better off caching the responses in a database.

  12. hi

    i’ve built a simple meta box for my client to add the vimeo ID and have it open in a lightbox – there are up to 8 on a portfolio page

    the php code I use in my template is which echos 18846937 or whatever the client has entered

    what i would love to do is for the above function to pull the id in that metabox to pull the thumbnail

    is there a way to integrate in the above function?

  13. ooops code stripped

    see here http://www.designerstalk.com/forums/help-me/60519-some-wordpress-vimeo-php-help.html#post710400

  14. [...] inserted into a mysql table. What I used for this was Vimeo service for the videos. Also thanks to soapboxdave for the function to retrieve the info from Vimeo’s [...]

  15. Hey great man totally worked for me, I added a few more things to it, in case anybody here needs it is more than welcome to take a look.. http://adsanti.wordpress.com/

    Basically I load videos and using this function load the thumbnails end result a video playlist.. :)

    thanks btw gave u total credit for this, thanks again…

  16. Hi,

    What would be the solution for auto-generating thumbnails to appear on a WordPress Articles summary page — which, in displaying an abstract of the posts, strips the Vimeo altogether. Is there a code snippet that can grab the thumbnail from the individual post, and then display it within the abstract?

    Thanks!

  17. I would do a regex search to find the string http://vimeo.com/**** and then pull the video id from that string. Finally run it through the function above to grab the info. Probably will just take a little bit of fancy regex footwork (definitely not my forte!)

  18. Thank you, this was perfect

  19. [...] в файле functions.php специальную функцию (помог мне в этом вот этот материал), возвращающую ссылку на миниатюру, [...]

  20. Thanks you so much, it’s works :)

  21. [...] party reference(s); http://www.soapboxdave.com/2010/04/getting-the-vimeo-thumbnail/ - Vimeo Thumbnail Tutorial This entry was posted in Uncategorized by admin. Bookmark the [...]

  22. ahh thank you so much. this is exactly what i’ve been looking for!

  23. If it’s useful to anyone, here’s a version that lets you specify the size of thumbnail you want (from the what the API provides): https://gist.github.com/pragmatic-web/6306792

  24. Can I hire you to help me set up a a video player with thumbnails feeding from a vimeo channel?

    Brad

Leave a Reply