Class: Gauguin::ImageRecolorer
- Inherits:
-
Object
- Object
- Gauguin::ImageRecolorer
- Defined in:
- lib/gauguin/image_recolorer.rb
Instance Method Summary collapse
-
#initialize(image) ⇒ ImageRecolorer
constructor
A new instance of ImageRecolorer.
- #recolor(new_colors) ⇒ Object
Constructor Details
#initialize(image) ⇒ ImageRecolorer
Returns a new instance of ImageRecolorer.
3 4 5 |
# File 'lib/gauguin/image_recolorer.rb', line 3 def initialize(image) @image = image.dup end |
Instance Method Details
#recolor(new_colors) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gauguin/image_recolorer.rb', line 7 def recolor(new_colors) columns = @image.columns rows = @image.rows new_image = Image.blank(columns, rows) (0...columns).each do |column| (0...rows).each do |row| image_pixel = @image.pixel_color(column, row) next if image_pixel.transparent? color = Color.new(*image_pixel.to_rgb) new_color = new_colors[color] next unless new_color new_image.pixel_color(column, row, new_color.to_s) end end new_image end |