How to remove black border of Youtube image

扶醉桌前 提交于 2021-01-28 19:00:02

问题


I got a lot of examples here how to get Youtube image. But if video is non-standard format, for example, vertical, black frame appears on the image.

I found interesting link on this site where it can be cut by GET query: http://img.youtube.com/vi/XkOpbLBzPsY/hqdefault.jpg

http://img.youtube.com/vi/XkOpbLBzPsY/hqdefault.jpg?custom=true&w=196&h=110&stc=true&jpg444=true&jpgq=90&sp=68&sigh=Gv-oyTIgA39e7UG01pZ2RiGbwSo

.. I tried out with my image, but nothing happened, and not any info on what these parameters are for.

The question is: if we can do that as in above urls, how can I get these parameters info? If not, is there any other way to remove black frame?

Is it possible to get such clear image if we know Youtube code only?


回答1:


You're looking for the 16:9 yt:aspectratio format of the youtube thumbnail. Try using the image URL provided in this SO thread:

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

Tried this and it works. Hope that helps.




回答2:


So finally I could do by:

<a href="#">
    <div style="background:url(<?php echo $url ?>) center no-repeat;
                background-size:cover;
                height:100px;
                width:50px;">
    </div>
</a>

Unfortunately not with the help of youtube api.



来源:https://stackoverflow.com/questions/40890029/how-to-remove-black-border-of-youtube-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!