class Halation::Engine

Performs modifications to the image Exif data.

Attributes

config[R]
image_extensions[RW]

Array of image extensions to search for.

roll[R]
silent[RW]

Suppress output to stdout if true.

Public Class Methods

new(opts = {}) click to toggle source

@option opts [String] :config_path (nil)

Override the config file that should be used.

@option opts [String] :working_dir (“.”)

Override the working directory (contains images and roll.yml).

@option opts [Array<String>] :image_extensions

Override the list of image extensions to search for.

@option opts [Boolean] :silent

Suppress output to stdout.
# File lib/halation/engine.rb, line 29
def initialize(opts = {})
  config_path = opts[:config_path]
  @silent = !!opts[:silent]
  @working_dir = File.expand_path(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
run(opts = {}) click to toggle source

@see run

# File lib/halation/engine.rb, line 17
def self.run(opts = {})
  new(opts).run
end

Public Instance Methods

image_files() click to toggle source

@return [Array<String>] detected image files to process, in ascending

alphabetical order.
# 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() click to toggle source

Process the batch of images.

# 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

Private Instance Methods