Home >Backend Development >PHP Tutorial >How to Get YouTube Video Thumbnails Using PHP and cURL?

How to Get YouTube Video Thumbnails Using PHP and cURL?

Barbara Streisand
Barbara StreisandOriginal
2024-12-18 16:37:12825browse

How to Get YouTube Video Thumbnails Using PHP and cURL?

How to Retrieve YouTube Video Thumbnails using PHP and cURL

Question:

How to use PHP and cURL Get thumbnail associated with YouTube video from YouTube API?

Answer:

Each YouTube video has four generated images. Their format can be predicted as follows:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

The first in the list is a full-size image, the others are thumbnail images. The default thumbnail image (i.e. one of 1.jpg, 2.jpg, 3.jpg) is:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

For a high-quality version of the thumbnail, use a URL similar to the following:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

There is also a medium quality version of the thumbnail, using something similar to HQ URL:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

For the standard definition version of the thumbnail, use a URL similar to:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg

For the maximum resolution version of the thumbnail, use something like The following URLs:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

All the above URLs are also available via HTTP. Additionally, in the example URL above, the slightly shorter hostname i3.ytimg.com could replace img.youtube.com.

Alternatively, you can use the YouTube Data API (v3) to get the thumbnail image.

The above is the detailed content of How to Get YouTube Video Thumbnails Using PHP and cURL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn