Skip to content

Commit 65274ab

Browse files
author
Christian Jeffries
committed
The output hash now includes the geometry options
1 parent 32bf365 commit 65274ab

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

lib/paperclip/paperclip_processors/transcoder.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ def initialize file, options = {}, attachment = nil
1414
@cli = ::Av.cli
1515
@meta = ::Av.cli.identify(@file.path)
1616
@whiny = options[:whiny].nil? ? true : options[:whiny]
17-
18-
@convert_options = options[:convert_options]
17+
18+
@convert_options = set_convert_options(options)
19+
1920
@format = options[:format]
20-
21+
2122
@geometry = options[:geometry]
2223
unless @geometry.nil?
2324
modifier = @geometry[0]
@@ -28,22 +29,24 @@ def initialize file, options = {}, attachment = nil
2829
@enlarge_only = @keep_aspect && modifier == '<'
2930
@shrink_only = @keep_aspect && modifier == '>'
3031
end
31-
32+
3233
@time = options[:time].nil? ? 3 : options[:time]
3334
@auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate]
3435
@pad_color = options[:pad_color].nil? ? "black" : options[:pad_color]
35-
36+
37+
@convert_options[:output][:s] = format_geometry(@geometry) if @gemotry.present?
38+
3639
attachment.instance_write(:meta, @meta) if attachment
3740
end
38-
41+
3942
# Performs the transcoding of the +file+ into a thumbnail/video. Returns the Tempfile
4043
# that contains the new image/video.
4144
def make
4245
::Av.logger = Paperclip.logger
4346
@cli.add_source @file
4447
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
4548
dst.binmode
46-
49+
4750
if @meta
4851
log "Transocding supported file #{@file.path}"
4952
@cli.add_source(@file.path)
@@ -76,10 +79,21 @@ def make
7679
end
7780
dst
7881
end
79-
82+
8083
def log message
8184
Paperclip.log "[transcoder] #{message}"
8285
end
86+
87+
def set_convert_options options
88+
return options[:convert_options] if options[:convert_options].present?
89+
options[:convert_options] = {output: {}}
90+
return options[:convert_options]
91+
end
92+
93+
def format_geometry geometry
94+
return unless geometry.present?
95+
return geometry.gsub(/[#!<>)]/, '')
96+
end
8397
end
8498

8599
class Attachment

0 commit comments

Comments
 (0)