How to get the average or main color from an image with javascript?

后端 未结 5 1460
失恋的感觉
失恋的感觉 2020-12-30 12:41

what i want is to the the HEX or the RGB average value from an image to the another div background this color.

So if i upload an image with a ot of red i get somethi

5条回答
  •  再見小時候
    2020-12-30 13:44

    • Put image on canvas.
    • Get 2D context.
    • Loop through pixels, and store each r,g,b value. If you find the same, increment it once.
    • Loop through stored r,g,b values and take note of largest r,g,b value.
    • Convert r,g,b to hex.

提交回复
热议问题