Skip to content

Instantly share code, notes, and snippets.

@starmer
Created February 5, 2012 19:03
Show Gist options
  • Select an option

  • Save starmer/1747277 to your computer and use it in GitHub Desktop.

Select an option

Save starmer/1747277 to your computer and use it in GitHub Desktop.
Create a diptych (combine two images together)
require 'rubygems'
require 'RMagick'
include Magick
if ARGV.length < 4
puts "Usage: ruby diptych.rb <new image> <left image> <right image> <width>"
else
left_img = Image.read(ARGV[1])[0];
right_img = Image.read(ARGV[2])[0];
if(left_img.rows != right_img.rows)
puts "Waring: The images aren't the same height"
end
image = Image.new(ARGV[3].to_i, right_img.rows.to_i) {
self.background_color = "white"
}
image.composite!(left_img, 0, 0, OverCompositeOp)
image.composite!(right_img, ARGV[3].to_i - right_img.columns.to_i, 0, OverCompositeOp)
image.write(ARGV[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment