1

I have a collection of images that have been laid out in a rectangle to look like a collage. How can I take those images and create a single image out of them in Ruby?

For example I have three images that I want placed in the image as follows:

Image 1: (0,0) - (300,400)

Image 2: (350, 0) - (500, 200)

Image 3: (350, 220) - (500, 400)

Wesley Tansey
  • 4,555
  • 10
  • 42
  • 69

2 Answers2

5

You can try something like this with RMagick:

require 'RMagick'

bg     = Image.read('bg.png') # may be a background image...
image1 = Image.read('image1.png')
image2 = Image.read('image2.png')
image3 = Image.read('image3.png')


bg.composite!(image1,   0,   0, OverCompositeOp)
bg.composite!(image2, 350,   0, OverCompositeOp)
bg.composite!(image3, 350, 220, OverCompositeOp)

bg.write('collage.png')
Pioz
  • 6,051
  • 4
  • 48
  • 67
  • is it possible space the images in the collage? So to have a 5 pixels of white space between each image and the next, as well as each image and the border? – dee May 13 '13 at 16:12
1

you probably want to use an image library like RMagick ... http://www.imagemagick.org/RMagick/doc/

Tilo
  • 33,354
  • 5
  • 79
  • 106