Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions lib/paperclip/paperclip_processors/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def initialize file, options = {}, attachment = nil
@cli = ::Av.cli
@meta = ::Av.cli.identify(@file.path)
@whiny = options[:whiny].nil? ? true : options[:whiny]

@convert_options = options[:convert_options]

@convert_options = set_convert_options(options)

@format = options[:format]

@geometry = options[:geometry]
unless @geometry.nil?
modifier = @geometry[0]
Expand All @@ -28,22 +29,24 @@ def initialize file, options = {}, attachment = nil
@enlarge_only = @keep_aspect && modifier == '<'
@shrink_only = @keep_aspect && modifier == '>'
end

@time = options[:time].nil? ? 3 : options[:time]
@auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate]
@pad_color = options[:pad_color].nil? ? "black" : options[:pad_color]


@convert_options[:output][:s] = format_geometry(@geometry) if @gemotry.present?

attachment.instance_write(:meta, @meta) if attachment
end

# Performs the transcoding of the +file+ into a thumbnail/video. Returns the Tempfile
# that contains the new image/video.
def make
::Av.logger = Paperclip.logger
@cli.add_source @file
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
dst.binmode

if @meta
log "Transocding supported file #{@file.path}"
@cli.add_source(@file.path)
Expand Down Expand Up @@ -76,10 +79,21 @@ def make
end
dst
end

def log message
Paperclip.log "[transcoder] #{message}"
end

def set_convert_options options
return options[:convert_options] if options[:convert_options].present?
options[:convert_options] = {output: {}}
return options[:convert_options]
end

def format_geometry geometry
return unless geometry.present?
return geometry.gsub(/[#!<>)]/, '')
end
end

class Attachment
Expand Down