Wednesday, 24 July 2013

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.
  1. //Youtube URL
  2. https://www.youtube.com/watch?v=5wqbC3_ZOQg
Now we can explode the URL and get the video ID (In this case 5wqbC3_ZOQg) using php.
  1. //explode the url to get video id and save the id to a variable
  2. $fetch=explode("v=", $url);
  3. $videoid=$fetch[1];
Now pass this video id to the img src tag
  1. //Display the image
  2. //Display 1st thumbnail
  3. echo '<img src="http://img.youtube.com/vi/'.$videoid.'/1.jpg" height="90" width="100">';
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.
  1. //Display 1st thumbnail
  2. echo '<img src="http://img.youtube.com/vi/'.$videoid.'/2.jpg" height="90" width="100">';
Hope that you like this article if so please share the article. Thank You !

1 comment:

  1. Hey really fantastic video. thanks for share!! Visit my site- Youtube Support Call Toll Free No +1-800-231-4635.

    ReplyDelete