lib/greyscale.rb
#
# Convert an image from RGB to greyscale using type algorithm.
# @param image [ChunkyPNG::Image]
# @param type [Symbol] one of :avg, :luma, or :light
#
# @return [type] [description]
Convert an image from RGB to greyscale using type algorithm.
Convert an image from RGB to greyscale using type algorithm .
def greyscale(image, type)
      (0...image.width).each do |x|
        (0...image.height).each do |y|
          pixel = image[x, y]
          rgb_values = [
            ChunkyPNG::Color.r(pixel),
            ChunkyPNG::Color.g(pixel),
            ChunkyPNG::Color.b(pixel)
          ]
          color = send(type, *rgb_values).to_i
          image[x, y] = ChunkyPNG::Color.rgb(color, color, color)
        end
      end
    end
def greyscale ( image , type ) ( 0 ... image . width ) . each do | x | ( 0 ... image . height ) . each do | y | pixel = image [ x , y ] rgb_values = [ ChunkyPNG :: Color . r ( pixel ) , ChunkyPNG :: Color . g ( pixel ) , ChunkyPNG :: Color . b ( pixel ) ] color = send ( type , * rgb_values ) . to_i image [ x , y ] = ChunkyPNG :: Color . rgb ( color , color , color ) end end end
Convert an image from RGB to greyscale using type algorithm.
Convert an image from RGB to greyscale using type algorithm .
None
type
image
<not_specific>
type
one of :avg, :luma, or :light
one of : avg : luma or : light
<not_specific>
None