Skip to content
animorio
IT
Back to the library

Photo palette picker

Images, HoverGSAP, Canvas, CSS onlyAdvancedCompressed weight: Demo 11 KBGSAP 28 KBFreeDownload the zip

Someone searched for “palette from image”, “color extractor” and “eyedropper”, and the site found nothing right. Here is the panel of a made-up design app, Hue: a real photo of a beach at dusk and, beside it, five colours actually extracted from its pixels. Hover a colour and only its zones stay lit in the photo while the rest fades to grey, as a marker settles on the spot where that colour is purest. On the photo the eyedropper follows the pointer with a loupe that magnifies the pixels, and the hex underneath rolls digit by digit; a click copies it. Minimal style.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Photo palette picker" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Palette from a photo</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the palette panel of a made-up design app, Hue: five swatches taken from the real pixels of the photo,
         the zones of a colour lighting up when you point at its swatch, and an eyedropper with a pixel loupe -->
    <section class="card" data-card aria-labelledby="pp-title">
      <header class="head">
        <span class="brand"><svg viewBox="0 0 18 18" aria-hidden="true"><circle cx="9" cy="9" r="6.2"></circle><path d="M9 2.8v12.4M3.6 6.1l10.8 5.8"></path></svg>Hue</span>
        <h1 class="head__title" id="pp-title">Palette from photo</h1>
        <span class="head__meta" data-meta>5 colours</span>
      </header>

      <div class="body">
        <div class="photo" data-photo>
          <img class="photo__img" src="costa.webp" width="960" height="640" alt="A beach at dusk under a pink sky, with dark rocks and pale sand" data-img>
          <canvas class="photo__veil" data-veil aria-hidden="true"></canvas>
          <span class="mark" data-mark aria-hidden="true"><span class="mark__ring"></span><span class="mark__dot"></span></span>
          <div class="loupe" data-loupe aria-hidden="true">
            <canvas class="loupe__px" data-loupe-px width="132" height="132"></canvas>
            <span class="loupe__cell"></span>
            <span class="loupe__chip"><span class="loupe__sw" data-loupe-sw></span><span class="hex" data-loupe-hex>#000000</span></span>
          </div>
          <span class="copied" data-copied aria-hidden="true"><svg viewBox="0 0 16 16"><path d="M3.5 8.4l3 3 6-6.6"></path></svg>Copied</span>
        </div>

        <ul class="swatches" data-swatches aria-label="Extracted colours"></ul>
      </div>

      <footer class="foot">
        <span class="foot__tip"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10.6 2.6l2.8 2.8-1.6 1.6-.9-.9-5.6 5.6H3.5v-1.8l5.6-5.6-.9-.9z"></path></svg>Point at the photo to pick, click to copy</span>
      </footer>
    </section>

    <svg class="ptr" data-ptr viewBox="0 0 24 24" aria-hidden="true"><path d="M5.2 3.4l13 8.2-5.6 1.3 3.3 5.9-2.4 1.3-3.3-5.9-4 4.1z"></path></svg>
    <p class="sr" aria-live="polite" data-live></p>
  </main>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

23 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Photo palette picker” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On a warm white ground, a wide card with a soft shadow and a hairline of light on its edge. At the top the logo of Hue, a made-up design app, and “Palette from photo”. On the left a real photo, a beach at dusk with dark rocks and a pink sky; on the right five swatches in a column, from lightest to darkest, each with its name, hex and the share of the photo it covers. On entry the photo settles from a slight zoom and the swatches arrive one by one, their hex rolling from #000000 to its value. Hover a swatch and in the photo the zones of the other colours fade into a warm grey with soft edges, the swatch lifts slightly and an accent line draws under it, and a white marker with an orange ring drops onto the spot where that colour is purest, with a small bounce. Hover the photo and the eyedropper appears: a round loupe magnifying the pixels around the pointer, with the chosen pixel framed and, underneath, a dark pill with the colour and the rolling hex; the nearest swatch lights up faintly. A click on the photo or on a swatch copies the hex and “Copied” appears at the top with a tick. The tour on its own hovers three swatches, then takes the eyedropper onto the photo and copies a colour.

How it works

Colours taken from the actual pixels

Once the photo has loaded it is drawn onto a small canvas, 160 pixels wide, and read with getImageData. A k-means runs on those pixels with a deterministic start (the mean, then each time the pixel farthest from the centres already chosen) and fourteen passes, with distances weighted like luminance (0.299, 0.587, 0.114): the same photo always gives the same palette. The centres are sorted from lightest to darkest and get a name from their hue and lightness.

The zones of a colour

For each colour a canvas of the same grid is prepared once: where the pixel belongs to another colour there is a warm grey made from its luminance, as opaque as VEIL, and where it belongs to that colour it stays transparent, with a soft falloff based on distance. On hover the new veil fades in over the old one, which fades out shortly after: no flashes between colours. The canvas is as big as the photo and has the same object-fit: cover.

The marker on the purest spot

For each colour the cell closest to its centre is found, with a small penalty for the photo's edges, and saved as a proportion. The marker goes there with back.out (MARK_SPRING), and the position is mapped to the screen with the same object-fit: cover maths, on resize too.

The eyedropper loupe

The full photo also sits in a canvas at its own size. On every move the pixel under the pointer is found and LOUPE_PIXELS pixels per side are copied into a round 132 pixel canvas with imageSmoothingEnabled off: the pixels show square. The loupe chases the pointer with quickTo (LOUPE_FOLLOW) and the hex changes by rolling only the digits that differ.

Rolling digits

Each hex character is a window one line tall: when it changes, the new digit is added underneath and both rise together over ROLL_TIME, one digit after another; at the end only the new one is left.

Values to change

NameFileDefaultWhat it changes
SWATCHESscript.js5How many colours are extracted from the photo (3 to 6).
LOUPE_PIXELSscript.js11How many photo pixels show across the loupe.
LOUPE_FOLLOWscript.js0.16How long the loupe takes to catch the pointer, in seconds.
VEILscript.js0.88How much the other colours' zones fade out.
HIGHLIGHT_TIMEscript.js0.45How long a colour's zones take to light up, in seconds.
MARK_SPRINGscript.js1.6How far the marker overshoots before settling.
ROLL_TIMEscript.js0.38How long the hex digits take to roll, in seconds.
LOOP_PAUSEscript.js1.6The pause at the end of the tour on its own, in seconds.

Try them in the Playground

When to use it

On the site or in the app of a design tool, a palette generator or a photo editor; in a photographer's or illustrator's portfolio, to show the colours of a piece; on a product page selling paints or fabrics from a photo.

On phones

In narrow or tall boxes the swatches go under the photo, in a row of five with only the colour and the hex; the photo takes its height in vh. On a phone there is no hover: a tap on the photo shows the loupe and copies, a tap on a swatch lights its zones and copies.

With reduced motion

No bounces, rolling digits or chasing loupe: the zones fade in, the marker appears already in place, the loupe sits under the pointer and the tour on its own does not start.

Pitfalls

  • getImageData needs a same-origin photo: the photo sits in the demo folder, next to the HTML.
  • The photo is object-fit: cover, so pointer and marker go through the same scale and offset maths: without it, the pixel read is not the one under the loupe.
  • The veil uses two stacked canvases that swap: redrawing the same canvas while visible flashed between colours.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 11 KB; the libraries: GSAP 28 KB.

Testing

Tested on 23 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations