paperclip-ffmpeg 0.3.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paperclip-ffmpeg/version.rb +1 -1
- data/lib/paperclip-ffmpeg.rb +23 -10
- metadata +1 -1
data/lib/paperclip-ffmpeg.rb
CHANGED
@@ -23,7 +23,9 @@ module Paperclip
|
|
23
23
|
|
24
24
|
@geometry = options[:geometry]
|
25
25
|
@file = file
|
26
|
-
@keep_aspect =
|
26
|
+
@keep_aspect = !@geometry.nil? && @geometry[-1,1] != '!'
|
27
|
+
@enlarge_only = @keep_aspect && @geometry[-1,1] == '<'
|
28
|
+
@shrink_only = @keep_aspect && @geometry[-1,1] == '>'
|
27
29
|
@whiny = options[:whiny].nil? ? true : options[:whiny]
|
28
30
|
@format = options[:format]
|
29
31
|
@time = options[:time].nil? ? 3 : options[:time]
|
@@ -41,30 +43,41 @@ module Paperclip
|
|
41
43
|
|
42
44
|
begin
|
43
45
|
parameters = []
|
44
|
-
parameters << '-y'
|
45
46
|
# Add geometry
|
46
47
|
if @geometry
|
48
|
+
# Extract target dimensions
|
47
49
|
if @geometry =~ /(\d*)x(\d*)/
|
48
50
|
target_width = $1
|
49
51
|
target_height = $2
|
50
52
|
end
|
53
|
+
# Only calculate target dimensions if we have current dimensions
|
51
54
|
unless @meta[:size].nil?
|
52
55
|
current_geometry = @meta[:size].split('x')
|
56
|
+
# Current width and height
|
53
57
|
current_width = current_geometry[0]
|
54
58
|
current_height = current_geometry[1]
|
55
59
|
if @keep_aspect
|
56
|
-
|
57
|
-
|
58
|
-
# Scaling down
|
60
|
+
if current_width.to_i >= target_width.to_i && !@enlarge_only
|
61
|
+
# Keep aspect ratio
|
59
62
|
width = target_width.to_i
|
60
63
|
height = (width.to_f / (@meta[:aspect].to_f)).to_i
|
61
|
-
|
62
|
-
#
|
64
|
+
elsif current_width.to_i < target_width.to_i && !@shrink_only
|
65
|
+
# Keep aspect ratio
|
66
|
+
width = target_width.to_i
|
67
|
+
height = (width.to_f / (@meta[:aspect].to_f)).to_i
|
68
|
+
# We should add the delta as a padding area
|
69
|
+
pad_h = (target_height.to_i - current_height.to_i) / 2
|
70
|
+
pad_w = (target_width.to_i - current_width.to_i) / 2
|
71
|
+
@convert_options[:vf] = "pad=#{width.to_i}:#{height.to_i}:#{pad_h}:#{pad_w}:black"
|
63
72
|
end
|
73
|
+
else
|
74
|
+
# Do not keep aspect ratio
|
75
|
+
width = target_width
|
76
|
+
height = target_height
|
64
77
|
end
|
65
|
-
|
66
|
-
|
67
|
-
@convert_options[:s] =
|
78
|
+
end
|
79
|
+
unless width.nil? || height.nil? || @convert_options[:vf]
|
80
|
+
@convert_options[:s] = "#{width.to_i}x#{height.to_i}"
|
68
81
|
end
|
69
82
|
end
|
70
83
|
# Add format
|