Color Thief won’t work …

前端 未结 4 1950
南笙
南笙 2020-12-18 04:42

I’d like to use Color Thief, a script which allows you to extract the dominant color of an image.

Unfortunately I’m not able to get the code to work. I’d like the do

4条回答
  •  猫巷女王i
    2020-12-18 05:10

    Murtnowski is correct in saying that the operation will fail if you run it against an image hosted on a different domain. If you are running it on an image hosted on your own domain, you just need to call getColor with an img element rather than a URL:

    HTML

    
    

    JS

    var sourceImage = document.getElementById("myImg");
    var colorThief = new ColorThief();
    colorThief.getColor(sourceImage);
    

提交回复
热议问题