Module: Colordom

Defined in:
lib/colordom.rb,
lib/colordom/color.rb,
lib/colordom/error.rb,
lib/colordom/image.rb,
lib/colordom/version.rb

Overview

Module that extracts dominant colors from images using native extension implemented in Rust.

Defined Under Namespace

Classes: Color, Error, Image

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.histogram(path, max_colors = 5) ⇒ Array<Color>

Get dominant colors using histogram quantization.

Parameters:

  • path (String, Pathname, File)
  • max_colors (Integer) (defaults to: 5)

Returns:

Raises:

  • (Error)

    if path is not a valid image



25
26
27
28
# File 'lib/colordom.rb', line 25

def histogram(path, max_colors = 5)
  image = Image.new(path)
  image.histogram(max_colors)
end

.kmeans(path, max_colors = 5) ⇒ Array<Color>

Get dominant colors using k-means clustering.

Parameters:

  • path (String, Pathname, File)
  • max_colors (Integer) (defaults to: 5)

Returns:

Raises:

  • (Error)

    if path is not a valid image



47
48
49
50
# File 'lib/colordom.rb', line 47

def kmeans(path, max_colors = 5)
  image = Image.new(path)
  image.kmeans(max_colors)
end

.mediancut(path, max_colors = 5) ⇒ Array<Color>

Get dominant colors using median cut quantization.

Parameters:

  • path (String, Pathname, File)
  • max_colors (Integer) (defaults to: 5)

Returns:

Raises:

  • (Error)

    if path is not a valid image



36
37
38
39
# File 'lib/colordom.rb', line 36

def mediancut(path, max_colors = 5)
  image = Image.new(path)
  image.mediancut(max_colors)
end