Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mauu-alpha/993c337e11ec2f65cf91 to your computer and use it in GitHub Desktop.
Save mauu-alpha/993c337e11ec2f65cf91 to your computer and use it in GitHub Desktop.
require "mini_magick"
module MiniMagick
class Image
def get_dominant_color
color = run_command("convert", path, "-format", "%c\n", "-colors", 1, "-depth", 8, "histogram:info:").split(' ');
# color = " 1764000: (208,195,161) #D0C3A1 srgb(208,195,161)\n\n"
{
hex: color[2],
rgb: color[1][1..-2].split(',')
}
end
end
end
i = MiniMagick::Image.open("/home/a.jpg")
p i.get_dominant_color()[:hex]
p i.get_dominant_color()[:rgb]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment