class PixelPicker::ColorName

Attributes

image_file[RW]

Public Class Methods

new(image_file) click to toggle source
# File lib/pixel_picker/color_name.rb, line 8
def initialize(image_file)
  self.image_file = image_file
end

Public Instance Methods

max() click to toggle source
# File lib/pixel_picker/color_name.rb, line 44
def max
  palette.max {|a, b| a[1] <=> b[1]}.first
end
min() click to toggle source
# File lib/pixel_picker/color_name.rb, line 48
def min
  palette.min {|a, b| a[1] <=> b[1]}.first
end
palette() click to toggle source
# File lib/pixel_picker/color_name.rb, line 12
def palette
  picture = ImageList.new(image_file)
  palette = {}
  picture.each_pixel do |pixel, c, r|
    next if pixel.to_hsla.last == 0
    case pixel.to_hsla.first
    when 0..20, 330..360
      color_name = :red
    when 20..50
      color_name = :orange
    when 50..69
      color_name = :yellow
    when 70..84
      color_name = :lime
    when 85..170
      color_name = :green
    when 171..191
      color_name = :aqua
    when 192..264
      color_name = :blue
    when 265..289
      color_name = :violet
    when 290..329
      color_name = :purple
    else
      next
    end
    palette[color_name].nil? ? palette[color_name] = 1 : palette[color_name] += 1
  end
  palette
end