-
-
Save bacoords/77ee4d13dfa76db03981cb4eb0df0c6f to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Grab the url of a publicly embeddable video hosted on vimeo | |
* @param str $video_url The "embed" url of a video | |
* @return str The url of the thumbnail, or false if there's an error | |
*/ | |
function grab_vimeo_thumbnail($vimeo_url){ | |
if( !$vimeo_url ) return false; | |
$data = json_decode( file_get_contents( 'http://vimeo.com/api/oembed.json?url=' . $vimeo_url ) ); | |
if( !$data ) return false; | |
return $data->thumbnail_url; | |
} |
Cool, thanks.
shame this only delivers the low res thumbnail. RIP v2 API getJSON solution
Really cool, thanks!
Thanks .. Found a solutions few hours and this is worked!
Works perfectly, thanks :)
Works perfectly, thanks dude! :) 👍
shame this only delivers the low res thumbnail. RIP v2 API getJSON solution
You can replace the resolution at end of URL string for 1920x1080
, if that helps @shaunkardinal.
You can replace the resolution at end of URL string for
1920x1080
, if that helps @shaunkardinal.
@monowales amazing! can you provide an example? something like thumbnail_large
or specifically include dimensions?
In Javascript I translated @bacoords code above, but returned:
...
return data.thumbnail_url.split('_')[0] + '_1920x1080';
Have a play, I'm fairly sure it will return any dimension you need, (it will crop though, if it's not the original ratio). I found the HD thumbs to be big enough, but still very small file size, 30-50kb. Only caveat is there might be instances where the underscore features elsewhere in the URL, but I don't think so.
For completeness, would it be this in PHP?
...
return explode($data->thumbnail_url, '_')[0]."_1920x1080";
unfortunately the PHP object only contains the one thumbnail_url, which is generally 640x360.
example https://vimeo.com/api/oembed.json?url=https://vimeo.com/311468941 returns
{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"https:\/\/vimeo.com\/","title":"olson kundig | space needle century project | seattle","author_name":"nic lehoux","author_url":"https:\/\/vimeo.com\/niclehoux","is_plus":"1","account_type":"plus","html":"<iframe src=\"https:\/\/player.vimeo.com\/video\/311468941?h=674979c981&app_id=122963\" width=\"640\" height=\"360\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture\" allowfullscreen title=\"olson kundig | space needle century project | seattle\"><\/iframe>","width":640,"height":360,"duration":158,"description":"","thumbnail_url":"https:\/\/i.vimeocdn.com\/video\/752300323-c9b7699f9dc14ec1484a39edca5506c5bf745e081cdab9d08fd9fc9c841d1183-d_640","thumbnail_width":640,"thumbnail_height":360,"thumbnail_url_with_play_button":"https:\/\/i.vimeocdn.com\/filter\/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F752300323-c9b7699f9dc14ec1484a39edca5506c5bf745e081cdab9d08fd9fc9c841d1183-d_640&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png","upload_date":"2019-01-15 10:03:56","video_id":311468941,"uri":"\/videos\/311468941"}
getting the 1080p image is still possible via JS, but delivering via PHP would be ideal! welcome any other takes here...
Hey @shaunkardinal, have a look at my last comment: you can use PHP to replace the ..._640
at the end of thumbnail_url
with any crop you like, eg _1920x1080
. It's undocumented, but works.
oh! i see the issue, a classic—the example code you gave had the separator/string mixed up! thanks again @monowales 🙏
return explode('_', $data->thumbnail_url)[0].'_1920x1080';
I just removed the resolution entirely and it give me the highest resolution image
return explode('_', $data->thumbnail_url)[0]
Thanks. This was very useful.