Class: VCSRuby::ContactSheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(video, capturer) ⇒ ContactSheet

Returns a new instance of ContactSheet.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/contact_sheet.rb', line 16

def initialize video, capturer
  @video = video
  @capturer = capturer
  @signature = "Created by Video Contact Sheet Ruby"
  initialize_filename

  if Configuration.instance.verbose?
    puts "Processing #{File.basename(video.full_path)}..."
  end

  return unless @video.valid?

  detect_video_properties

  @from = TimeIndex.new 0
  @to = @video.info.duration

  @timestamp = Configuration.instance.timestamp
  @softshadow = Configuration.instance.softshadow
  @polaroid = Configuration.instance.polaroid

  @tempdir = Dir.mktmpdir

  ObjectSpace.define_finalizer(self, self.class.finalize(@tempdir) )
  initialize_geometry(Configuration.instance.rows, Configuration.instance.columns, Configuration.instance.interval)

end

Instance Attribute Details

#aspect_ratioObject

Returns the value of attribute aspect_ratio.



13
14
15
# File 'lib/contact_sheet.rb', line 13

def aspect_ratio
  @aspect_ratio
end

#formatObject

Returns the value of attribute format.



13
14
15
# File 'lib/contact_sheet.rb', line 13

def format
  @format
end

#fromObject

Returns the value of attribute from.



14
15
16
# File 'lib/contact_sheet.rb', line 14

def from
  @from
end

#highlightObject

Returns the value of attribute highlight.



11
12
13
# File 'lib/contact_sheet.rb', line 11

def highlight
  @highlight
end

#lengthObject (readonly)

Returns the value of attribute length.



14
15
16
# File 'lib/contact_sheet.rb', line 14

def length
  @length
end

#polaroidObject

Returns the value of attribute polaroid.



12
13
14
# File 'lib/contact_sheet.rb', line 12

def polaroid
  @polaroid
end

#signatureObject

Returns the value of attribute signature.



11
12
13
# File 'lib/contact_sheet.rb', line 11

def signature
  @signature
end

#softshadowObject

Returns the value of attribute softshadow.



12
13
14
# File 'lib/contact_sheet.rb', line 12

def softshadow
  @softshadow
end

#thumbnail_heightObject

Returns the value of attribute thumbnail_height.



13
14
15
# File 'lib/contact_sheet.rb', line 13

def thumbnail_height
  @thumbnail_height
end

#thumbnail_widthObject

Returns the value of attribute thumbnail_width.



13
14
15
# File 'lib/contact_sheet.rb', line 13

def thumbnail_width
  @thumbnail_width
end

#timestampObject

Returns the value of attribute timestamp.



12
13
14
# File 'lib/contact_sheet.rb', line 12

def timestamp
  @timestamp
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/contact_sheet.rb', line 11

def title
  @title
end

#toObject

Returns the value of attribute to.



14
15
16
# File 'lib/contact_sheet.rb', line 14

def to
  @to
end

Instance Method Details

#buildObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/contact_sheet.rb', line 126

def build
  if (@video.info.duration.total_seconds < 1.0)
    puts "Video is shorter than 1 sec"
  else
    initialize_filters
    initialize_thumbnails
    capture_thumbnails

    puts "Composing standard contact sheet..." unless Configuration.instance.quiet?
    montage = splice_montage(montage_thumbs)

    image = MiniMagick::Image.open(montage)

    puts "Adding header and footer..." unless Configuration.instance.quiet?
    final = add_header_and_footer image

    puts "Done. Output wrote to '#{filename}'" unless Configuration.instance.quiet?
    FileUtils.mv(final, full_path)
  end
end

#columnsObject



75
76
77
# File 'lib/contact_sheet.rb', line 75

def columns
  @columns
end

#filenameObject



59
60
61
# File 'lib/contact_sheet.rb', line 59

def filename
  "#{@out_filename}#{@format}"
end

#full_pathObject



67
68
69
# File 'lib/contact_sheet.rb', line 67

def full_path
  File.join(@out_path, filename)
end

#initialize_filename(override = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/contact_sheet.rb', line 44

def initialize_filename override = nil
  @out_path = File.dirname(@video.full_path)
  @out_filename = File.basename(override || @video.full_path,'.*')

  extension = override ?  File.extname(override) : ''
  @format = extension.length > 0 ? extension : '.png'
end

#initialize_geometry(rows, columns, interval) ⇒ Object



52
53
54
55
56
57
# File 'lib/contact_sheet.rb', line 52

def initialize_geometry(rows, columns, interval)
  @has_interval = !!interval
  @rows = rows
  @columns = columns
  @interval = interval
end

#intervalObject



79
80
81
# File 'lib/contact_sheet.rb', line 79

def interval
  @interval || (@to - @from) / (number_of_caps)
end

#number_of_capsObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/contact_sheet.rb', line 83

def number_of_caps
  if @has_interval
    (@to - @from) / @interval
  else
    if @rows && @columns
      @rows * @columns
    else
      raise "you need at least 2 parameters from columns, rows and interval"
    end
  end
end

#rowsObject



71
72
73
# File 'lib/contact_sheet.rb', line 71

def rows
  @rows
end