Not sure if this is really RoR, but more a Ruby question. One way is to use RMagick, a wrapper around ImageMagick. RMagick is reportedly leaking memory and it can be painful to install Rmagick / Imagemagick. I had the best experience installing Imagemagick with brew (OS X).
require 'rubygems'
require 'rmagick'
width = 100
height = 100
data = Array.new(width) do
Array.new(height) do
[rand(255), rand(255), rand(255)]
end
end
img = Magick::Image.new(width, height)
data.each_with_index do |row, row_index|
row.each_with_index do |item, column_index|
img.pixel_color(row_index, column_index, "rgb(#{item.join(', ')})")
end
end
img.write('demo.bmp')
source
share