Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 2
- 3 4
- require 'rmagick'
- image_list = Magick::ImageList.new("image1.png", "image2.png", "image3.png")
- image_list.write("combine.png")
- require 'rmagick'
- class Combiner
- include Magick
- def self.combine
- #this will be the final image
- big_image = ImageList.new
- #this is an image containing first row of images
- first_row = ImageList.new
- #this is an image containing second row of images
- second_row = ImageList.new
- #adding images to the first row (Image.read returns an Array, this is why .first is needed)
- first_row.push(Image.read("1.png").first)
- first_row.push(Image.read("2.png").first)
- #adding first row to big image and specify that we want images in first row to be appended in a single image on the same row - argument false on append does that
- big_image.push (first_row.append(false))
- #same thing for second row
- second_row.push(Image.read("3.png").first)
- second_row.push(Image.read("4.jpg").first)
- big_image.push(second_row.append(false))
- #now we are saving the final image that is composed from 2 images by sepcify append with argument true meaning that each image will be on a separate row
- big_image.append(true).write("big_image.jpg")
- end
- end
- # Replace this with the path to the images you want to combine
- images = [
- "image1.jpg",
- "image2.jpg"
- ]
- processed_image = MiniMagick::Tool::Montage.new do |image|
- image.geometry "x700+0+0"
- image.tile "#{images.size}x1"
- images.each {|i| image << i}
- image << "output.jpg"
- end
Add Comment
Please, Sign In to add comment