删除视频缩略图上的黑条
我有一个画廊,用户可以在其中提交视频的 Youtube 链接,服务器会自动从 Youtube 获取缩略图。然而,许多视频的图像顶部和底部都包含黑条。我知道黑条的起源,但当我将缩略图大小调整为正方形时,黑条会干扰设计。
我尝试从上到下分析像素颜色,直到找不到黑色 (imagecolorat()),但它仍然留下一些接近黑色的颜色,因此小条仍然驻留在图像中。
有什么更有效的算法可以检查?
I have gallery where user can submit Youtube links to videos and server fetches the thumbnail from Youtube automatically. However, lots of videos contain black bars on top and bottom of the image. I know the origin of the black bars, but as i resize thumbnail to square, the black bars interfere with the design.
I have tried to analyze pixel color from top to bottom until no black color is found (imagecolorat()), but it still leaves some near-black color so the small bars still reside in the image.
What can be more effective algorythm to check for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案之一是做与 youtube 相同的事情。
如果您访问他们的网站,并查看图像和包装图像的元素,您将看到包装元素具有与此类似的 css:
他们使用的图像在顶部和底部(在该容器内)包含黑色区域,但它们使用css来隐藏它。
这意味着元素(在带有 att display:inline-block 的 youtube span 上)将小于实际图片,并且图片将像这样居中/定位,因此顶部和底部黑色区域将溢出较小的包装并被隐藏。
One of the solutions is to do same thing which youtube did.
If you visit their site, and look at the image and element that wraps image, you will see that wrap element have css similar to this one:
They are using image which contain black areas on top and bottom (within that container), but they used css to hide it.
This means that element (on youtube span with att display:inline-block) will be smaller then acctual picture, and picture will be centered/positioned like that so top and bottom black areas will overflow smaller wrap and will be hidden.
如果您想按颜色进行操作,wideimage 库(基于 GD)已经实现了此功能。该方法称为
autoCrop
,是一个 存在在线演示。这可能已经满足您的需求。
If you want to go by the color, the wideimage library (GD based) has this implemented already. The method is called
autoCrop
, an online demonstration exists.This might already fulfil your needs.
您应该检查视频的比例(4:3 或 16:9)并裁剪缩略图以保持该比例。不尝试检测颜色。
You should check the video's ratio (4:3 or 16:9) and crop the thumbnail to keep that ratio. Not trying to detect the color.