-
-
Save bartolsthoorn/f5383dbcb0d015a4f511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test.rb:14:in `[]': wrong number of arguments(2 for 1) (ArgumentError) | |
from image.rb:14:in `block (2 levels) in black_and_white_array' | |
from image.rb:13:in `times' | |
from image.rb:13:in `block in black_and_white_array' | |
from image.rb:11:in `times' | |
from image.rb:11:in `black_and_white_array' | |
from image.rb:27:in `<main>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chunky_png' | |
def is_dark?(color) | |
ChunkyPNG::Color.r(color) + | |
ChunkyPNG::Color.g(color) + | |
ChunkyPNG::Color.b(color) < 40 | |
end | |
def black_and_white_array(image) | |
array = Array.new | |
image.width.times do |x| | |
array[x] = Array.new | |
image.height.times do |y| | |
if is_dark? image[x,y] | |
image = ChunkyPNG::Color.rgba(0, 0, 0, 128) | |
else | |
image = ChunkyPNG::Color.rgba(255, 255, 255, 128) | |
end | |
end | |
end | |
image.save("#{Time.now.to_i.to_s}.png", :fast_rgba) | |
return array | |
end | |
# Image 1, the face of Charlie Sheen | |
image1 = ChunkyPNG::Image.from_file('image1.png') | |
array1 = black_and_white_array(image1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment