Reputation: 4605
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)
Upvotes: 1
Views: 1553
Reputation: 6321
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')
Upvotes: 5
Reputation: 33732
you probably want to use an image library like RMagick ... http://www.imagemagick.org/RMagick/doc/
Upvotes: 1