Guest User

Untitled

a guest
Jun 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. 1 2
  2. 3 4
  3.  
  4. require 'rmagick'
  5.  
  6. image_list = Magick::ImageList.new("image1.png", "image2.png", "image3.png")
  7. image_list.write("combine.png")
  8.  
  9. require 'rmagick'
  10. class Combiner
  11. include Magick
  12.  
  13. def self.combine
  14. #this will be the final image
  15. big_image = ImageList.new
  16.  
  17. #this is an image containing first row of images
  18. first_row = ImageList.new
  19. #this is an image containing second row of images
  20. second_row = ImageList.new
  21.  
  22. #adding images to the first row (Image.read returns an Array, this is why .first is needed)
  23. first_row.push(Image.read("1.png").first)
  24. first_row.push(Image.read("2.png").first)
  25.  
  26. #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
  27. big_image.push (first_row.append(false))
  28.  
  29. #same thing for second row
  30. second_row.push(Image.read("3.png").first)
  31. second_row.push(Image.read("4.jpg").first)
  32. big_image.push(second_row.append(false))
  33.  
  34. #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
  35. big_image.append(true).write("big_image.jpg")
  36. end
  37. end
  38.  
  39. # Replace this with the path to the images you want to combine
  40. images = [
  41. "image1.jpg",
  42. "image2.jpg"
  43. ]
  44.  
  45. processed_image = MiniMagick::Tool::Montage.new do |image|
  46. image.geometry "x700+0+0"
  47. image.tile "#{images.size}x1"
  48. images.each {|i| image << i}
  49. image << "output.jpg"
  50. end
Add Comment
Please, Sign In to add comment