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
Release: 2024-12-18 16:37:12
Original
820 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template