paperclip-ffmpeg 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paperclip-ffmpeg.rb +55 -40
- data/paperclip-ffmpeg.gemspec +1 -2
- metadata +2 -3
- data/lib/paperclip-ffmpeg/version.rb +0 -5
data/lib/paperclip-ffmpeg.rb
CHANGED
@@ -24,6 +24,7 @@ module Paperclip
|
|
24
24
|
@geometry = options[:geometry]
|
25
25
|
@file = file
|
26
26
|
@keep_aspect = !@geometry.nil? && @geometry[-1,1] != '!'
|
27
|
+
@pad_only = @keep_aspect && @geometry[-1,1] == '#'
|
27
28
|
@enlarge_only = @keep_aspect && @geometry[-1,1] == '<'
|
28
29
|
@shrink_only = @keep_aspect && @geometry[-1,1] == '>'
|
29
30
|
@whiny = options[:whiny].nil? ? true : options[:whiny]
|
@@ -41,58 +42,72 @@ module Paperclip
|
|
41
42
|
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
42
43
|
dst.binmode
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if @
|
60
|
-
if current_width.to_i
|
45
|
+
parameters = []
|
46
|
+
# Add geometry
|
47
|
+
if @geometry
|
48
|
+
# Extract target dimensions
|
49
|
+
if @geometry =~ /(\d*)x(\d*)/
|
50
|
+
target_width = $1
|
51
|
+
target_height = $2
|
52
|
+
end
|
53
|
+
# Only calculate target dimensions if we have current dimensions
|
54
|
+
unless @meta[:size].nil?
|
55
|
+
current_geometry = @meta[:size].split('x')
|
56
|
+
# Current width and height
|
57
|
+
current_width = current_geometry[0]
|
58
|
+
current_height = current_geometry[1]
|
59
|
+
if @keep_aspect
|
60
|
+
if @enlarge_only
|
61
|
+
if current_width.to_i < target_width.to_i
|
61
62
|
# Keep aspect ratio
|
62
63
|
width = target_width.to_i
|
63
64
|
height = (width.to_f / (@meta[:aspect].to_f)).to_i
|
64
|
-
|
65
|
+
@convert_options[:s] = "#{width.to_i}x#{height.to_i}"
|
66
|
+
else
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
elsif @shrink_only
|
70
|
+
if current_width.to_i > target_width.to_i
|
65
71
|
# Keep aspect ratio
|
66
72
|
width = target_width.to_i
|
67
73
|
height = (width.to_f / (@meta[:aspect].to_f)).to_i
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@convert_options[:vf] = "pad=#{width.to_i}:#{height.to_i}:#{pad_h}:#{pad_w}:black"
|
74
|
+
@convert_options[:s] = "#{width.to_i}x#{height.to_i}"
|
75
|
+
else
|
76
|
+
return nil
|
72
77
|
end
|
78
|
+
elsif @pad_only
|
79
|
+
# Keep aspect ratio
|
80
|
+
width = target_width.to_i
|
81
|
+
height = (width.to_f / (@meta[:aspect].to_f)).to_i
|
82
|
+
# We should add half the delta as a padding offset Y
|
83
|
+
pad_y = (target_height.to_f - height.to_f).abs.to_i / 2
|
84
|
+
@convert_options[:vf] = "scale=#{width}:-1,pad=#{width.to_i}:#{target_height.to_i}:0:#{pad_y}:black"
|
73
85
|
else
|
74
|
-
#
|
75
|
-
width = target_width
|
76
|
-
height =
|
86
|
+
# Keep aspect ratio
|
87
|
+
width = target_width.to_i
|
88
|
+
height = (width.to_f / (@meta[:aspect].to_f)).to_i
|
89
|
+
@convert_options[:s] = "#{width.to_i}x#{height.to_i}"
|
77
90
|
end
|
91
|
+
else
|
92
|
+
# Do not keep aspect ratio
|
93
|
+
@convert_options[:s] = "#{target_width.to_i}x#{target_height.to_i}"
|
78
94
|
end
|
79
|
-
unless width.nil? || height.nil? || @convert_options[:vf]
|
80
|
-
@convert_options[:s] = "#{width.to_i}x#{height.to_i}"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
# Add format
|
84
|
-
case @format
|
85
|
-
when 'jpg', 'jpeg', 'png', 'gif' # Images
|
86
|
-
@convert_options[:f] = 'image2'
|
87
|
-
@convert_options[:ss] = @time
|
88
|
-
@convert_options[:vframes] = 1
|
89
95
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
96
|
+
end
|
97
|
+
# Add format
|
98
|
+
case @format
|
99
|
+
when 'jpg', 'jpeg', 'png', 'gif' # Images
|
100
|
+
@convert_options[:f] = 'image2'
|
101
|
+
@convert_options[:ss] = @time
|
102
|
+
@convert_options[:vframes] = 1
|
103
|
+
end
|
104
|
+
|
105
|
+
parameters << '-i :source'
|
106
|
+
parameters << @convert_options.map { |k,v| "-#{k.to_s} #{v} "}
|
107
|
+
parameters << ":dest"
|
94
108
|
|
95
|
-
|
109
|
+
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
110
|
+
begin
|
96
111
|
success = Paperclip.run("ffmpeg", parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path))
|
97
112
|
|
98
113
|
rescue PaperclipCommandLineError => e
|
data/paperclip-ffmpeg.gemspec
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "paperclip-ffmpeg/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = "paperclip-ffmpeg"
|
7
|
-
s.version =
|
6
|
+
s.version = '0.6.2'
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
8
|
s.authors = ["Omar Abdel-Wahab"]
|
10
9
|
s.email = ["owahab@gmail.com"]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: paperclip-ffmpeg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Omar Abdel-Wahab
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-03 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -39,7 +39,6 @@ files:
|
|
39
39
|
- README.md
|
40
40
|
- Rakefile
|
41
41
|
- lib/paperclip-ffmpeg.rb
|
42
|
-
- lib/paperclip-ffmpeg/version.rb
|
43
42
|
- paperclip-ffmpeg.gemspec
|
44
43
|
has_rdoc: true
|
45
44
|
homepage: http://github.com/owahab/paperclip-ffmpeg
|