Class: Snapshot::ScreenshotRotate

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/screenshot_rotate.rb

Overview

This class takes care of rotating images

Instance Method Summary collapse

Instance Method Details

#rotate(path) ⇒ Object



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/snapshot/screenshot_rotate.rb', line 12

def rotate(path)
  Dir.glob([path, '/**/*.png'].join('/')).each do |file|
    UI.verbose "Rotating '#{file}'"

    command = nil
    if file.end_with? "landscapeleft.png"
      command = "sips -r -90 '#{file}'"
    elsif file.end_with? "landscaperight.png"
      command = "sips -r 90 '#{file}'"
    elsif file.end_with? "portrait_upsidedown.png"
      command = "sips -r 180 '#{file}'"
    end

    next unless command

    # Only rotate if we need to
    PTY.spawn(command) do |r, w, pid|
      r.sync
      r.each do |line|
        # We need to read this otherwise things hang
      end
      ::Process.wait pid
    end
  end
end

#run(path) ⇒ Object

Parameters:

  • The (String)

    path in which the screenshots are located in



7
8
9
10
# File 'lib/snapshot/screenshot_rotate.rb', line 7

def run(path)
  UI.verbose "Rotating the screenshots (if necessary)"
  rotate(path)
end