Get Video Thumbnail from Youtube URL Using PHP

Sometime it’s necessary to display the Thumbnail Image of a youtube video from URL. So in this tutorial am going to example you how to get the thumbnail image of a video from youtube. Here am using PHP to obtain the output.

Get Video Thumbnail from Youtube using Yoututbe URL

To fetch the video thumbnail image from Youtube, first we need the get the video id from given URL.

Live Demo Download

Now we can explode the youtube URL and get the video ID (In this case 5wqbC3_ZOQg) using php.

//explode the url to get video id and save the id to a variable
$fetch=explode("v=", $url);

Now pass this video id to the img src tag

//Display the image 
//Display 1st thumbnail
echo '<img src="'.$videoid.'/1.jpg" width="100" height="90" />';

This will display you the first thumbnail image. if you want to use second or third image just change the number in image src tag.

//Display 1st thumbnail
echo '<img src="'.$videoid.'/2.jpg" width="100" height="90" />';

Hope that you like this article if so please share the article. If you want you can download the example file above. Thank You !

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>