gpt4 book ai didi

javascript - 从 YouTube 缩略图抓取调色板

转载 作者:搜寻专家 更新时间:2023-10-31 23:38:10 31 4
gpt4 key购买 nike

我正在尝试从 YouTube 缩略图中获取调色板,以更好地将 YouTube 视频与整个网站设计融合在一起,我想知道是否有任何方法可以做到这一点?

我试过使用 color-thief ( https://github.com/lokesh/color-thief ) 和这段代码(没有运气):

var img = new Image();
img.onload = function () {
var colorThief = new ColorThief();
colorThief.getColor(img);
};
img.crossOrigin = 'Anonymous';
img.src = 'http://img.youtube.com/vi/NuEfvIca0XU/mqdefault.jpg

由此我得到了这个错误:

Image from origin 'http://img.youtube.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access

有什么方法可以绕过这个,或者在不从 YouTube 下载缩略图并将其保存在我的服务器上的情况下获取调色板?

最佳答案

找到了解决方案,但它涉及通过 http://cors-anywhere.herokuapp.com/ 传递图像链接

这给我们留下了:

var img = new Image();
img.onload = function () {
var colorThief = new ColorThief();
colorThief.getColor(img);
};
img.crossOrigin = 'Anonymous';
img.src = 'http://cors-anywhere.herokuapp.com/http://img.youtube.com/vi/'+id+'/mqdefault.jpg';

关于javascript - 从 YouTube 缩略图抓取调色板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30731209/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com