I want to get youtube highest thumbnail \"maxresdefault.jpg\"
Like this one
http://i.ytimg.com/vi/Cj6ho1-G6tw/maxresdefault.jpg
I\'m using this simple ph
You can use getimagesize()
and check if the image exists (there's file_exists()
too, but it may not work very well, in this case).
You can use this function to fetch the greatest resolution screenshot of a particular video.
Code:
function fetch_highest_res ($videoid) {
$resolutions = array('maxresdefault', 'hqdefault', 'mqdefault');
foreach($resolutions as $res) {
$imgUrl = "http://i.ytimg.com/vi/$videoid/$res.jpg";
if(@getimagesize(($imgUrl)))
return $imgUrl;
}
}
Usage:
echo fetch_highest_res('Cj6ho1-G6tw').'
';
echo fetch_highest_res('VGazSZUYyf4');
Output:
http://i.ytimg.com/vi/Cj6ho1-G6tw/maxresdefault.jpg
http://i.ytimg.com/vi/VGazSZUYyf4/hqdefault.jpg
Note: This may not be the best solution, and it's a work-around if you don't want to use the API.