0

I have already gone through the following links

-> Removing black borders 4:3 on youtube thumbnails

-> How to remove black border of Youtube image

-> https://stackoverflow.com/questions/13220715/removing-black-borders-43-on-youtube-thumbnails#:~:text=To%20remove%20the%20black%20borders,which%20come%20from%20that%20domain.

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(&quot;https://img.youtube.com/vi/8yxZ-k0xI9s/0.jpg&quot;); 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.''

mqdefault image

  1. Many videos with different sizes(height & width )
  2. Preview image black border length also varying

Can anyone please give some idea how to achive this ?

Thanks in Advance

1 Answers1

0

Here are some examples I adapted (by checking the embed video and view its CSS styles):

Example # 1:

.ytp-cued-thumbnail-overlay-image {
  background-size: cover;
  -moz-background-size: cover;
  -webkit-background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  width: 100%;
  height: 100%;
  position: absolute;
}
<p>Image 1: </p>
<div class="ytp-cued-thumbnail-overlay-image" style="background-image: url('https://i.ytimg.com/vi/3TJgmUGFHqw/sddefault.jpg');"></div>

Example # 2:

.ytp-cued-thumbnail-overlay-image {
  background-size: cover;
  -moz-background-size: cover;
  -webkit-background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  width: 100%;
  height: 100%;
  position: absolute;
}
<p>Image 2: </p>
<div class="ytp-cued-thumbnail-overlay-image" style="background-image: url('https://i.ytimg.com/vi/NNgYId7b4j0/maxresdefault.jpg');"></div>
Mauricio Arias Olave
  • 2,259
  • 4
  • 25
  • 70