class Elrio::Runner

Public Class Methods

new(cap_inset_detector = CapInsetDetector.new, image_optimizer = ImageOptimizer.new) click to toggle source
# File lib/elrio/runner.rb, line 5
def initialize(cap_inset_detector = CapInsetDetector.new, image_optimizer = ImageOptimizer.new)
  @cap_inset_detector = cap_inset_detector
  @image_optimizer = image_optimizer
end

Public Instance Methods

analyze(path) click to toggle source
# File lib/elrio/runner.rb, line 10
def analyze(path)
  image = ChunkyPNG::Image.from_file(path)
  scale = PointSize.from_filename(path)
  insets = @cap_inset_detector.detect_cap_insets(image)
  insets / scale
end
optimize(path) click to toggle source
# File lib/elrio/runner.rb, line 17
def optimize(path)
  image = ChunkyPNG::Image.from_file(path)
  scale = PointSize.from_filename(path)
  insets = @cap_inset_detector.detect_cap_insets(image)
  point_insets = insets / scale

  optimized_image = @image_optimizer.optimize(image, insets)

  if optimized_image
    optimized_path = optimized_path_for(path)
    optimized_image.save(optimized_path)
  end

  point_insets
end

Private Instance Methods

optimized_path_for(path) click to toggle source
# File lib/elrio/runner.rb, line 35
def optimized_path_for(path)
  File.join(
    File.dirname(path),
    File.basename(path, ".*") + "-optimized.png"
  )
end