使用rmagick“模糊”现有的单个图像拼接?

时间:2013-02-05 19:25:56

标签: rmagick mosaic

尝试使用rmagick拼接图像。

如何“拼接模糊”现有图像,使其代表马赛克的图片?

像: enter image description here

1 个答案:

答案 0 :(得分:2)

这是使用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