Color Thief won’t work …

前端 未结 4 1946
南笙
南笙 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条回答
  •  一生所求
    2020-12-18 05:22

    I've had the same problem, and solved it this way :

    // get my image url
    var imageUrl = '//myimage.ulr.com';
    // than create an image elm, the sizes are needed. 360x360 on this case
    var image = new Image(360, 360);
    
    
    image.onload = function(){
        // act only after image load
        console.log(image);
    
        // than colorThief and get the color value 
        var colorThief = new ColorThief();          
        var color = colorThief.getColor(image);
        console.log(color);
    };
    image.src = imageUrl;
    

    Hope it helps anyone

提交回复
热议问题