Reputation: 788
I'm trying to use PHP to retrieve a list of recent uploaded videos from a Youtube channel however the thumbnails are all in 4:3 format with black borders at the top and bottom. I am using the following to retrieve the thumbnails:
$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
and this to import them:
<img src="<?php echo $thumbnail;?>"/>
The youtube API website and various other Q&A websites say you can use the variable
yt:name='mqdefault'
to retrieve the 16:9 thumbnails with no borders, however I have no clue where to incorporate this into the PHP?
Upvotes: 2
Views: 5692
Reputation: 138
http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
You would need you url to look similar to one of those.
Not sure what:
(string)$media->group->thumbnail[0]->attributes()->url;
is returning but I would take a look at that URL and make sure it resembles something similar to above.
For you below example you want you URL to resemble this.
http://img.youtube.com/vi/0GQPoyMr30o/mqdefault.jpg
http://img.youtube.com/vi/0GQPoyMr30o/maxresdefault.jpg
Try doing something like this:
<?php
$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
$thumbnail = str_replace('0.jpg', 'mqdefault.jpg', $thumbnail);
?>
<img src="<?php echo $thumbnail; ?>" />
Upvotes: 10