Is it possible to automatically get the main color of an element in css / javascript? [duplicate]

Can css or javascript pick automatically the main color of an image for example? like on spotify where the website /app automatically adapts to whatever is the color of the artwork of an album

As for now i’m using a var that I set individually in each html pages:

    <style>:root {
  --primary-color: #9dff00;</style>

and indeed then in my css:

    color: var(--primary-color);