Class: MiniMagick::Montage

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_magick.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(images, output_extension, options = {}) ⇒ Object

To create a montage simply call Montage.new with the images you want combine, the path to the output file and any command line options you may want. You will be returned a MiniMagick::Image instance for the new montage:

image1 = MiniMagick::Image.open('alice.png')
image2 = MiniMagick::Image.open('bob.png')
output_image = MiniMagick::Composite.new([image1, image2], 'jpg', :background => '#336699')
output_image.write('montage.jpg')

The above example would combine the two images into a new JPEG file using a background color of #336699. The the image is saved using the standard Image.save method.

The ‘montage’ script has several options, see here: www.imagemagick.org/script/montage.php



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/mini_magick.rb', line 394

def self.new(images, output_extension, options={})
  begin
    tempfile = Tempfile.new(['mini_magick', ".#{output_extension}"])
    tempfile.binmode
  ensure
    tempfile.close if tempfile
  end

  args = options.collect { |key,value| "-#{key.to_s} #{value.to_s}" }  # collect hash parts into arguments
  images.each do |image|
    args.push image.path
  end
  args.push(tempfile.path)

  # This is a little hacky - cannikin's CommandeRunner would be a useful
  # alternative (http://github.com/cannikin/mini_magick).
  Image.new(images.first.path, tempfile).run_command('montage', *args)
  return Image.open(tempfile.path)
end

Instance Method Details

#runObject



414
415
# File 'lib/mini_magick.rb', line 414

def run
end