4

Trying to mosaic an image with rmagick.

How would one "mosaic blur" an existing image making the picture that it represents mosaic'ed ?

Like: enter image description here

Rubytastic
  • 15,001
  • 18
  • 87
  • 175

1 Answers1

2

This is how you do a mosaic using RMagick

#!/home/software/ruby-1.8.5/bin/ruby -w
require 'RMagick'

# Demonstrate the mosaic method

a = Magick::ImageList.new

letter = 'A'
26.times do
    # 'M' is not the same size as the other letters.
    if letter != 'M'
        a.read("images/Button_"+letter+".gif")
    end
    letter.succ!
end

# Make a copy of "a" with all the images quarter-sized
b = Magick::ImageList.new
page = Magick::Rectangle.new(0,0,0,0)
a.scene = 0
5.times do |i|
    5.times do |j|
        b << a.scale(0.25)
        page.x = j * b.columns
        page.y = i * b.rows
        b.page = page
        (a.scene += 1) rescue a.scene = 0
    end
end

# Make a 5x5 mosaic
mosaic = b.mosaic
mosaic.write("mosaic.gif")
# mosaic.display
exit
MZaragoza
  • 10,108
  • 9
  • 71
  • 116
  • 5
    you can watch a video that is close to this but not mosaic http://railscasts.com/episodes/374-image-manipulation – MZaragoza Oct 04 '13 at 04:46
  • could not get this to work instantly but I get the point try to hack something together based on your example. thank you – Rubytastic Oct 07 '13 at 07:09