7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/wallbum/image_packer.rb', line 7
def pack_images(size_x, size_y, images, &block)
count = images.size
puts "Making wallpaper with #{images.size} images"
root = Rectangle.new(nil, 0, 0, size_x, size_y)
while (root.child_count < count) do
root.largest_child.split
end
images.each do |fname|
rect = root.empty_child
rect.image = Image.new(fname)
end
wallpaper = Magick::Image.new(size_x, size_y) do
self.background_color = 'black'
end
root.all_children.each do |rect|
wallpaper.composite!(rect.image.img.resize_to_fill(rect.width, rect.height),
rect.x,
rect.y,
Magick::OverCompositeOp)
end
yield wallpaper
end
|