Class: PixelPicker::ColorName
- Inherits:
-
Object
- Object
- PixelPicker::ColorName
- Includes:
- Magick
- Defined in:
- lib/pixel_picker/color_name.rb
Instance Attribute Summary collapse
-
#image_file ⇒ Object
Returns the value of attribute image_file.
Instance Method Summary collapse
-
#initialize(image_file) ⇒ ColorName
constructor
A new instance of ColorName.
- #max ⇒ Object
- #min ⇒ Object
- #palette ⇒ Object
Constructor Details
#initialize(image_file) ⇒ ColorName
Returns a new instance of ColorName.
8 9 10 |
# File 'lib/pixel_picker/color_name.rb', line 8 def initialize(image_file) self.image_file = image_file end |
Instance Attribute Details
#image_file ⇒ Object
Returns the value of attribute image_file.
6 7 8 |
# File 'lib/pixel_picker/color_name.rb', line 6 def image_file @image_file end |
Instance Method Details
#max ⇒ Object
44 45 46 |
# File 'lib/pixel_picker/color_name.rb', line 44 def max palette.max {|a, b| a[1] <=> b[1]}.first end |
#min ⇒ Object
48 49 50 |
# File 'lib/pixel_picker/color_name.rb', line 48 def min palette.min {|a, b| a[1] <=> b[1]}.first end |
#palette ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |