Class: Elrio::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/elrio/runner.rb

Instance Method Summary collapse

Instance Method Details

#analyze(path) ⇒ Object



5
6
7
8
9
# File 'lib/elrio/runner.rb', line 5

def analyze(path)
  image = ChunkyPNG::Image.from_file(path)
  image_optimizer = ImageOptimizer.new(is_retina?(path))
  image_optimizer.detect_cap_insets(image)
end

#optimize(path) ⇒ Object



11
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
# File 'lib/elrio/runner.rb', line 11

def optimize(path)
  retina = is_retina?(path)

  if retina
    opt_suffix = "[email protected]"
    opt_base = path.sub(/@2x/, '')
  else
    opt_suffix = "-optimized.png"
    opt_base = path
  end

  optimized_path = File.join(
    File.dirname(opt_base),
    File.basename(opt_base, ".*") + opt_suffix
  )

  image = ChunkyPNG::Image.from_file(path)

  image_optimizer = ImageOptimizer.new(retina)
  insets = image_optimizer.detect_cap_insets(image)

  optimized = image_optimizer.optimize(image, insets)
  optimized.save(optimized_path) if optimized

  insets
end