Extract bright colors from an image

Curated ago by @adam

Description

Sometimes you need to pull out a color from an image. This could be for a placeholder, for a background, or for any other use. Often the “most common” color from an image is going to be shades of grey or brown – not the most exciting color to expand on.

Instead, if you extract those common colors and then run them through a luminosity check you can find which colors are the most “luminous”. This helps filter the common colors down and helps pick one that shines.

You can tweak the “luma” number and generate colors that are even more vibrant or less vibrant. If you turn the value up too high you might not get any results in the image. Here’s an example of what some of the colors extracted using this formula look like.

1
2
3
4
5
6
7
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.2'

gem 'mini_magick'
gem 'miro', github: 'adamfortuna/miro'

The official Miro gem hasn’t been updated in a few years. My branch just has a few tweaks to keep it running.