class TimestampMaker
Constants
- COORDINATE_ORIGINS
Attributes
handlers[RW]
instance[W]
mime_recognizer[RW]
Public Class Methods
instance()
click to toggle source
# File lib/timestamp_maker.rb, line 21 def self.instance @instance ||= new end
new( mime_recognizer: MimeRecognizers::Marcel.new, handlers: [ Handlers::ImageMagick.new( time_zone_lookuper: TimeZoneLookupers::Wheretz.new ), Handlers::Ffmpeg.new( time_zone_lookuper: TimeZoneLookupers::Wheretz.new ) ] )
click to toggle source
# File lib/timestamp_maker.rb, line 25 def initialize( mime_recognizer: MimeRecognizers::Marcel.new, handlers: [ Handlers::ImageMagick.new( time_zone_lookuper: TimeZoneLookupers::Wheretz.new ), Handlers::Ffmpeg.new( time_zone_lookuper: TimeZoneLookupers::Wheretz.new ) ] ) @mime_recognizer = mime_recognizer @handlers = handlers end
Public Instance Methods
add_timestamp( input_path, output_path, format: '%Y-%m-%d %H:%M:%S', time: nil, font_size: 32, font_family: 'Sans', font_color: 'white', background_color: '
click to toggle source
# File lib/timestamp_maker.rb, line 40 def add_timestamp( input_path, output_path, format: '%Y-%m-%d %H:%M:%S', time: nil, font_size: 32, font_family: 'Sans', font_color: 'white', background_color: '#000000B3', time_zone: nil, coordinate_origin: 'top-left', x: 32, y: 32, font_padding: 8 ) mime_type = mime_recognizer.recognize(input_path) handler = handlers.find { |i| i.accept?(mime_type) } raise "Unsupported MIME type: ##{mime_type}" if handler.nil? time = handler.creation_time(input_path) if time.nil? raise ArgumentError unless time.is_a?(Time) time.localtime(TZInfo::Timezone.get(time_zone)) unless time_zone.nil? unless COORDINATE_ORIGINS.include?(coordinate_origin) raise( ArgumentError, "coordinate origin should be one of #{COORDINATE_ORIGINS.join(',')}" ) end handler.add_timestamp( input_path, output_path, time, format: format, font_size: font_size, font_family: font_family, font_color: font_color, background_color: background_color, coordinate_origin: coordinate_origin, x: x, y: y, font_padding: font_padding ) end