Class: Halation::Engine
- Inherits:
-
Object
- Object
- Halation::Engine
- Defined in:
- lib/halation/engine.rb
Overview
Performs modifications to the image Exif data.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#image_extensions ⇒ Object
Array of image extensions to search for.
-
#roll ⇒ Object
readonly
Returns the value of attribute roll.
-
#silent ⇒ Object
Suppress output to stdout if true.
Class Method Summary collapse
Instance Method Summary collapse
-
#image_files ⇒ Array<String>
Detected image files to process, in ascending alphabetical order.
-
#initialize(opts = {}) ⇒ Engine
constructor
A new instance of Engine.
-
#run ⇒ Object
Process the batch of images.
Constructor Details
#initialize(opts = {}) ⇒ Engine
Returns a new instance of Engine.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/halation/engine.rb', line 29 def initialize(opts = {}) config_path = opts[:config_path] @silent = !!opts[:silent] @working_dir = File.(opts[:working_dir] || ".") @image_extensions = opts[:image_extensions] || ["tif", "tiff", "jpg", "jpeg"] @config = Config.new @config.load_file(config_path) @roll = Roll.new @roll.load_file("#{@working_dir}/roll.yml") end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/halation/engine.rb', line 13 def config @config end |
#image_extensions ⇒ Object
Array of image extensions to search for.
9 10 11 |
# File 'lib/halation/engine.rb', line 9 def image_extensions @image_extensions end |
#roll ⇒ Object (readonly)
Returns the value of attribute roll.
14 15 16 |
# File 'lib/halation/engine.rb', line 14 def roll @roll end |
#silent ⇒ Object
Suppress output to stdout if true.
11 12 13 |
# File 'lib/halation/engine.rb', line 11 def silent @silent end |
Class Method Details
.run(opts = {}) ⇒ Object
17 18 19 |
# File 'lib/halation/engine.rb', line 17 def self.run(opts = {}) new(opts).run end |
Instance Method Details
#image_files ⇒ Array<String>
Returns detected image files to process, in ascending alphabetical order.
44 45 46 47 |
# File 'lib/halation/engine.rb', line 44 def image_files Dir[*@image_extensions.map { |ext| "#{@working_dir}/*.#{ext}" }] .sort[0...@roll.frames.count] end |
#run ⇒ Object
Process the batch of images.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/halation/engine.rb', line 50 def run _image_files = image_files specified_camera = @roll.camera camera = @config.cameras.find { |camera| camera.tag == specified_camera } raise "Camera #{specified_camera} not found in config.yml" unless camera @roll.frames.each_with_index do |frame, i| break if i >= _image_files.count specified_lens = frame.lens || @roll.lens lens = camera.lenses.find { |lens| lens.tag == specified_lens } raise "Lens #{specified_lens} not found for frame #{frame.number}" unless lens relative_path = _image_files[i].gsub(%r(^#{Dir.pwd}/), "") puts "Processing frame #{frame.number}\n #{relative_path}" unless @silent ExifToolImage.new(_image_files[i]).tap do |exif| exif["Artist"] = @roll.artist || @config.artist exif["Copyright"] = template_copyright(@config, @roll, frame) exif["DateTimeOriginal"] = frame.date_captured || @roll.date_captured exif["CreateDate"] = frame.date_scanned || @roll.date_scanned exif["Make"] = camera.make exif["Model"] = camera.model exif["LensModel"] = lens.model exif["ISO"] = @roll.iso exif["ExposureTime"] = frame.shutter || @roll.shutter exif["FNumber"] = frame.aperture || @roll.aperture exif["FocalLength"] = frame.focal_length || lens.focal_length || @roll.focal_length exif["Flash"] = frame.flash ? 1 : 0 exif["Orientation"] = frame.orientation || 1 exif.save end end end |