I have already gone through the following links
-> Removing black borders 4:3 on youtube thumbnails
-> How to remove black border of Youtube image
We have many videos in our project with different size(width & height).
Tried following solutions
Solution 1: crop or adjust the height
HTML
<div class="thumb">
<img src="...">
</div>
CSS
.thumb {
overflow: hidden;
}
.thumb img {
margin: -10% 0;
width: 100%;
}
Failing for some sceanrios , because of image black border size is varying for few images.
Screenshot for reference
Image with less black border Image with more black border
Solution 2: Use it as a background image, center it and change height.
.youtubePreview {
background:url('http://img.youtube.com/vi/aOPGepdbfpo/0.jpg') center no-repeat;
height:204px;
width:480px;
}
or
also tried with background-image
<div class="bgimg" style="background-image: url("https://img.youtube.com/vi/8yxZ-k0xI9s/0.jpg"); height:275px "></div>
Example: 450*275 failing
We have video with different sizes so it works for some width and its failing for other widths.
Solution 3: Get Youtube Images not having black borders ( use mqdefault.jpg instead of 0.jpg)
followed this link How do I get a YouTube video thumbnail from the YouTube API?
Based on above link came to know that mqdefault.jpg images not havin black borders
We using url for images https://img.youtube.com/vi/YOUTUBEVIDEOID/0.jpg
so replaced with https://img.youtube.com/vi/YOUTUBEVIDEOID/mqdefault.jpg
But unfortunately few mqdefault images having black borders at left and right side.''
- Many videos with different sizes(height & width )
- Preview image black border length also varying
Can anyone please give some idea how to achive this ?
Thanks in Advance