Class: ImageGenie::Montage
- Defined in:
- lib/image_genie/montage.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#filenames ⇒ Object
Returns the value of attribute filenames.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Montage
constructor
A new instance of Montage.
Methods inherited from Command
Constructor Details
#initialize(options = {}) ⇒ Montage
Returns a new instance of Montage.
6 7 8 9 |
# File 'lib/image_genie/montage.rb', line 6 def initialize(={}) self.filenames = [] self. = end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/image_genie/montage.rb', line 4 def filename @filename end |
#filenames ⇒ Object
Returns the value of attribute filenames.
4 5 6 |
# File 'lib/image_genie/montage.rb', line 4 def filenames @filenames end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/image_genie/montage.rb', line 4 def @options end |
Class Method Details
.run(filenames, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/image_genie/montage.rb', line 12 def self.run(filenames, ={}) raise(UnableToLocateBinaryError, 'montage') if path_for(:montage).blank? # Montage hates when you attempt to give it files with a path in it, so we # need to change to the system specified temp directory to do our work. Dir.chdir(Dir::tmpdir) # Create a temp file that will be all component files of this montage temp_image_file = Tempfile.new(['montage','.jpg']) temp_image_list_file = Tempfile.new(['montage_image_filenames','.txt']) temp_image_list_file.puts filenames.join("\n") temp_image_list_file.rewind logger.info("#{self.name} Attempting to make a montage of #{filenames.size} files") command = make_command(path_for(:montage), "@\"#{File.basename(temp_image_list_file.path)}\"", , "jpeg:-") begin execute(command) do |pid,stdin,stdout,stderr| while !stdout.eof? temp_image_file.puts stdout.readline end temp_image_file.rewind # Still foggy on if we need to wait until we read from STDOUT before waiting, or if # we wait until we read STDOUT and STDERR. ignored, status = Process::waitpid2 pid handle_errors(stderr,status,MontageError) end rescue Exception => e # Close the tempfile before raising temp_image_file.close raise ensure logger.info("#{self.name} Cleaning up files") temp_image_list_file.close end return temp_image_file end |