lib/contact_sheet.rb in vcs_ruby-0.8.5 vs lib/contact_sheet.rb in vcs_ruby-1.0.0

- old
+ new

@@ -9,24 +9,30 @@ require 'vcs' module VCSRuby class ContactSheet attr_accessor :capturer, :format, :signature, :title, :highlight + attr_accessor :softshadow, :timestamp, :polaroid attr_reader :thumbnail_width, :thumbnail_height attr_reader :length, :from, :to - def initialize video, capturer = :any - @capturer = capturer - @configuration = Configuration.new + def initialize video, profile = nil + @capturer = :any + @configuration = Configuration.new profile @signature = "Created by Video Contact Sheet Ruby" initialize_capturers video initialize_filename(File.basename(@video, '.*')) puts "Processing #{File.basename(video)}..." unless Tools.quiet? detect_video_properties @thumbnails = [] + @filters = [] + @timestamp = @configuration.timestamp + @softshadow = @configuration.softshadow + @polaroid = @configuration.polaroid + @tempdir = Dir.mktmpdir ObjectSpace.define_finalizer(self, self.class.finalize(@tempdir) ) initialize_geometry(@configuration.rows, @configuration.columns, @configuration.interval) @@ -113,17 +119,19 @@ FileUtils.rm_r tempdir end end def build + selected_capturer.format = selected_capturer.available_formats.first + initialize_filters initialize_thumbnails capture_thumbnails puts "Composing standard contact sheet..." unless Tools.quiet? - s = splice_montage(montage_thumbs) + montage = splice_montage(montage_thumbs) - image = MiniMagick::Image.open(s) + image = MiniMagick::Image.open(montage) puts "Adding header and footer..." unless Tools.quiet? final = add_header_and_footer image puts "Done. Output wrote to '#{filename}'" unless Tools.quiet? @@ -156,19 +164,27 @@ def available_capturers @capturers.select{ |c| c.available? } end + def initialize_filters + @filters << :resize_filter + @filters << :softshadow_filter if softshadow + @filters << :timestamp_filter if timestamp + @filters << :polaroid_filter if polaroid + end + def initialize_thumbnails time = @from (1..number_of_caps).each do |i| thumb = Thumbnail.new selected_capturer, @video, @configuration thumb.width = thumbnail_width thumb.height = thumbnail_height thumb.time = (time += interval) - thumb.image_path = File::join(@tempdir, "th#{"%03d" % i}.png") + thumb.image_path = File::join(@tempdir, "th#{"%03d" % i}.#{selected_capturer.format.to_s}") + thumb.filters.push(*@filters) @thumbnails << thumb end end @@ -217,15 +233,28 @@ end return file_path end def splice_montage montage_path + if softshadow + left = @configuration.padding + 3 + top = @configuration.padding + 5 + bottom = right = @configuration.padding + else + left = right = top = bottom = @configuration.padding + end + + file_path = File::join(@tempdir, 'spliced.png') MiniMagick::Tool::Convert.new do |convert| convert << montage_path convert.background @configuration.contact_background - convert.splice '5x10' + + convert.splice "#{left}x#{top}" + convert.gravity 'SouthEast' + convert.splice "#{right}x#{bottom}" + convert << file_path end file_path end @@ -293,10 +322,10 @@ if @configuration.header_font.exists? a.font @configuration.header_font.path end a.pointsize @configuration.header_font.size a.background @configuration.header_background - a.fill 'Black' + a.fill @configuration.header_color a.stack do |b| b.gravity 'West' b.stack do |c| c.label 'Filename: ' if @configuration.header_font.exists?