phpyoutubeyoutube-apivideo-thumbnails

Get YouTube video thumbnail and use it with PHP


How can I access thumbnail collection of a YouTube video using the link of the video from the YouTube API. I want thumbnails to be displayed on website using PHP using the video id stored in a variable for example $link.


Solution

  • YouTube stores many different types of thumbnails on its server for different devices. You can access it by using the video id which every YouTube video has. You can display the images on your website using a variable $link which holds the id of the video and substituting it in the place for video_ID in the link.

    Low quality thumbnail:

    http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/sddefault.jpg
    

    Medium quality thumbnail:

    http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/mqdefault.jpg
    

    High quality thumbnail:

    http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/hqdefault.jpg
    

    Maximum quality thumbnail:

    http://img.youtube.com/vi/<YouTube_Video_ID_HERE>/maxresdefault.jpg
    

    Example:

    If you want to access the thumbnail of the following video:

    https://www.youtube.com/watch?v=Q-GYwhqDo6o
    

    Video ID : Q-GYwhqDo6o

    So, this is how video thumbnail link looks like:

    http://img.youtube.com/vi/Q-GYwhqDo6o/mqdefault.jpg
    

    Hope it helps. Enjoy coding.