Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Get video thumbnail from vimeo

This function uses vimeo API to get information about video (including thumbnail). It takes new or old embed code or url of vimeo video and returns array with information about video.

<?php
function get_vimeo_thumb($vimeo)
{
    $id = $vimeo;
    //try new embed code
    preg_match('/http://player.vimeo.com/video/([^?"]*)/is', 
                $vimeo, $match);
    if(!empty($match))
    {
        //found id
        $id = $match[1];
    }
    else
    {
        //try old embed code
        preg_match('/http://[w.]*vimeo.com/moogaloop.swf?clip_id=([^&"]*)/is', 
                $vimeo, $match);
        if(!empty($match))
        {
            //found id
            $id = $match[1];
        }
        else
        {
            //try url
            preg_match('/http://[w.]*vimeo.com/([^&"]*)/is', 
                $vimeo, $match);
            if(!empty($match))
            {
                //found id
                $id = $match[1];
            }
        }
    }
    //forming API url
    $url = "http://vimeo.com/api/v2/video/".$id.".json";
    //curl request
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlData = curl_exec($curl);
    curl_close($curl);
    
    //decoding json structure into array
    return current(json_decode($curlData, true));
}

$vimeo = 'http://vimeo.com/12083674';
$arr = get_vimeo_thumb($vimeo);

echo "<pre>";
print_r($arr);
echo "</pre>";

echo "<img src='".$arr["thumbnail_medium"]."'/>";
?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus