Class: ImageGenie::Montage

Inherits:
Command
  • Object
show all
Defined in:
lib/image_genie/montage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filenames, options = {}) ⇒ Montage

Returns a new instance of Montage.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/image_genie/montage.rb', line 18

def initialize(filenames,options={})
  logger.info("#{self.class.name} Attempting to make montage of #{filenames.count} files")
  self.filenames = filenames
  self.exception_class = MontageError
  raise(UnableToLocateBinaryError, 'montage') if path_for(:montage).blank?
  self.options = options
  # 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)
  self.temp_image_file = Tempfile.new(['montage','.jpg'])
  self.temp_image_list_file = Tempfile.new(['montage_image_filenames','.txt']) 
  # Create a temp file that will be all component files of this montage
  temp_image_list_file.puts filenames.join("\n")
  temp_image_list_file.rewind
  super(self)
end

Instance Attribute Details

#filenamesObject

Returns the value of attribute filenames.



4
5
6
# File 'lib/image_genie/montage.rb', line 4

def filenames
  @filenames
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/image_genie/montage.rb', line 4

def options
  @options
end

#temp_image_fileObject

Returns the value of attribute temp_image_file.



4
5
6
# File 'lib/image_genie/montage.rb', line 4

def temp_image_file
  @temp_image_file
end

#temp_image_list_fileObject

Returns the value of attribute temp_image_list_file.



4
5
6
# File 'lib/image_genie/montage.rb', line 4

def temp_image_list_file
  @temp_image_list_file
end

Instance Method Details

#cleanupObject



13
14
15
16
# File 'lib/image_genie/montage.rb', line 13

def cleanup
  logger.info("#{self.class.name} Cleaning up files")
  temp_image_list_file.close
end

#outputObject



6
7
8
9
10
11
# File 'lib/image_genie/montage.rb', line 6

def output
  while !stdout.eof?
    temp_image_file.puts stdout.readline
  end
  temp_image_file.rewind
end

#runObject



35
36
37
38
39
# File 'lib/image_genie/montage.rb', line 35

def run
  command = make_command(path_for(:montage), "@\"#{File.basename(temp_image_list_file.path)}\"", options, "jpeg:-")
  execute(command)
  return temp_image_file
end