Skip to content

Instantly share code, notes, and snippets.

@rodrigoalvesvieira
Last active October 23, 2018 13:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rodrigoalvesvieira/5041672 to your computer and use it in GitHub Desktop.
Save rodrigoalvesvieira/5041672 to your computer and use it in GitHub Desktop.
Concatenate multiple images into one using ImageMagick and Ruby
#!/usr/bin/env ruby
=begin
Rodrigo Alves
Februrary 26, 2013
A program to concatenate multiple images into one
Call it from the command line and pass it n parameters, the first n-1 parameters
are the names of the images from which you wanna create another image and the n-th
parameter is the name of the final, concatenated image
example: ./concat-images.rb rodrigo.png bia.png brothers.png
will create a file named brothers.png that contains all other images passed to the program
but before you can use this code like above, you should tell chmod to let this program run:
chmod +x concat-images.rb
Enjoy this code!
=end
require "rmagick"
include Magick
def concat_images(*images)
images_files = images[0..images.length - 2];
file_name = images.last
image_final = Magick::ImageList.new(*images_files)
result = image_final.montage
result.write file_name
end
concat_images(*ARGV)
@brunocoelho
Copy link

So simple, really looks good. 👍

@ad1992
Copy link

ad1992 commented Feb 12, 2017

This is helpful 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment