Last active
October 23, 2018 13:11
-
-
Save rodrigoalvesvieira/5041672 to your computer and use it in GitHub Desktop.
Concatenate multiple images into one using ImageMagick and Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So simple, really looks good. 👍