Image Color Picker: how it works and how to build one
Pick any pixel’s color from an image as HEX, RGB and HSL. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Open an image and click anywhere to get that pixel’s color. A zoomed loupe helps you hit the exact pixel, and picked colors are kept in a list you can copy.
When to use it
- Matching colors from a design or screenshot
- Getting a brand’s exact hex from a logo
- Checking colors in a photo
How to use it
- Open an image.
- Move over it and click to pick.
- Copy HEX, RGB or HSL.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/image-color-picker
How it works
The image is drawn onto a canvas at full size. When the pointer moves, its screen position is scaled to image pixels and getImageData(x, y, 1, 1) returns that pixel’s red, green, blue and alpha values.
The loupe is a small second canvas that draws an 11×11 pixel area scaled up 10× with smoothing turned off, so each pixel shows as a sharp square.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
pickColor.ts (ts)
export function pixelAt(canvas: HTMLCanvasElement, e: PointerEvent) {
const r = canvas.getBoundingClientRect();
const x = Math.floor(((e.clientX - r.left) / r.width) * canvas.width);
const y = Math.floor(((e.clientY - r.top) / r.height) * canvas.height);
const [red, green, blue] = canvas.getContext("2d", { willReadFrequently: true })!.getImageData(x, y, 1, 1).data;
return "#" + [red, green, blue].map((v) => v.toString(16).padStart(2, "0")).join("");
}
// In Chrome and Edge you can also pick from anywhere on screen:
// const { sRGBHex } = await new EyeDropper().open();
Make it production-ready
- Support pasting screenshots from the clipboard.
- Average a 3×3 area for noisy photos.
Questions
Can I pick from a screenshot?
Yes. Take a screenshot, then paste it here with Ctrl+V or open the file.
Free, runs in your browser, nothing is uploaded.