YouTube is the world’s favorite video search engine. It’s very common now people use YouTube video in their websites/blog. Today’s tutorial we are demonstrating how to fetch YouTube video thumbnail using PHP.
Basically this simple PHP script fetch YouTube thumbnail image from a full YouTube video URL.
Get Thumbnail Image URL from YouTube Embed Code
$videoUrl = "https://www.youtube.com/watch?v=8zy7wGbQgfw"; parse_str( parse_url( $videoUrl, PHP_URL_QUERY ), $my_array_of_vars ); $ytID = $my_array_of_vars['v']; //gets video ID print "https://img.youtube.com/vi/<?php print $ytID?>/maxresdefault.jpg"; print "https://img.youtube.com/vi/<?php print $ytID?>/mqdefault.jpg"; print "https://img.youtube.com/vi/<?php print $ytID?>/hqdefault.jpg"; print "https://img.youtube.com/vi/<?php print $ytID?>/sddefault.jpg"; print "https://img.youtube.com/vi/<?php print $ytID?>/default.jpg";
To get different thumbnails
https://img.youtube.com/vi/<?php print $ytID?>/0.jpg https://img.youtube.com/vi/<?php print $ytID?>/1.jpg https://img.youtube.com/vi/<?php print $ytID?>/2.jpg https://img.youtube.com/vi/<?php print $ytID?>/3.jpg
Read this post to get more details about how to get YouTube thumbnail images manually.
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.