The following post shows how you can retrieve any YouTube video thumbnails in PHP without using the YouTube api. I needed this for a onetime solution to get some thumbnails for a few videos and using the api seemed a little time consuming. So here goes.
YouTube video thumbnail structure
The urls from where you can get the thumbnails are shown below. Each video generates around 4 standard thumbnails. The first image is a full size image while others are smaller thumbnail images. You can easily try the following urls in the browser by replacing the ‘youtube-video-id’ part with the corresponding videos id.
http://img.youtube.com/vi/youtube-video-id/0.jpg
http://img.youtube.com/vi/youtube-video-id/1.jpg
http://img.youtube.com/vi/youtube-video-id/2.jpg
http://img.youtube.com/vi/youtube-video-id/3.jpg
# Default thumbnail
http://img.youtube.com/vi/youtube-video-id/default.jpg
The id is the last part of the YouTube url or the id in the ‘v’ GET variable.
# Example, the id here is 'VSB4wGIdDwo'
Other than the above mentioned urls there are a few specific ones listed below which are also available.
Standard quality version:
http://img.youtube.com/vi/youtube-video-id/sddefault.jpg
Medium quality version:
http://img.youtube.com/vi/youtube-video-id/mqdefault.jpg
High quality version:
http://img.youtube.com/vi/youtube-video-id/hqdefault.jpg
Maximum quality version:
http://img.youtube.com/vi/youtube-video-id/maxresdefault.jpg
Note: Not all image types may be available for a video.
Getting images using PHP
Below is the PHP code to download thumbnails when given the video id.
Thanks for the tip: nice to be able to get those images.
If you know the URL you can use $image = file_get_contents($youtube_thumb_url); instead of CURL.
If the URL is not valid/reachable, PHP issues a warning and $image is bool(false).