miniatura 0.3.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/lib/miniatura.rb +63 -48
- data/lib/miniatura/generate_command.rb +1 -1
- data/lib/miniatura/logger.rb +6 -11
- data/lib/miniatura/options.rb +25 -22
- data/lib/miniatura/version.rb +1 -1
- data/miniatura-0.5.0.gem +0 -0
- data/miniatura.gemspec +13 -13
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b64b736961cca4c381da24644a7dabfbe157406ccfc8299ba90c978d725d65c9
|
4
|
+
data.tar.gz: dff8ea8f1f98ff9e23d42a4f2279169cbed0b43db2fca534d1193f079e53ad97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53bbae3adfd914425d677645610eb4b76a7996ac954de7fa9b3a490dbe1ba4ba9db964068693548e786f83016a78c0a6e8b286af727fd47693bf730f209def74
|
7
|
+
data.tar.gz: d36384e59bc4c712b51133558ff668dadc794226d38da0459cfa771a750d59b64f24761003f0a57688ac317e2e2cb1bc5205b9aa214da772aaa1b1924ec9f797
|
data/.gitignore
CHANGED
data/lib/miniatura.rb
CHANGED
@@ -1,69 +1,84 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'open3'
|
2
|
+
require 'miniatura/version'
|
3
|
+
require 'miniatura/options'
|
4
|
+
require 'miniatura/logger'
|
5
|
+
require 'miniatura/generate_command'
|
6
6
|
|
7
7
|
module Miniatura
|
8
|
-
def generate_thumb
|
8
|
+
def generate_thumb(options = {})
|
9
|
+
@exit_code, @error = nil
|
10
|
+
raise Errno::ENOENT unless File.exist?(current_path)
|
9
11
|
options[:file_extension] ||= 'jpeg'
|
10
|
-
options[:logger] = Rails.logger
|
11
|
-
size = options[:size]
|
12
|
-
video = MiniExiftool.new(current_path)
|
13
|
-
orientation = video.rotation
|
14
12
|
options[:rotate] = 0
|
15
|
-
|
16
|
-
options[:
|
17
|
-
|
18
|
-
|
19
|
-
cmd
|
20
|
-
|
21
|
-
logger.info("Running command: #{cmd}")
|
22
|
-
exit_code, error = nil
|
23
|
-
raise Errno::ENOENT unless File.exist?(current_path)
|
24
|
-
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
25
|
-
error = stderr.read
|
26
|
-
exit_code = wait_thr.value
|
27
|
-
end
|
28
|
-
handle_exit_code(exit_code, error, logger)
|
13
|
+
options[:size] = determine_thumb_dimension_ratio_from_uploaded_video(options[:size])
|
14
|
+
tmp_path = generate_temp_file(options[:file_extension])
|
15
|
+
cmd = generate_command_for_thumbnail(options, tmp_path)
|
16
|
+
show_logs(cmd)
|
17
|
+
execute_command(cmd)
|
18
|
+
handle_exit_code(@exit_code, @error)
|
29
19
|
File.rename tmp_path, current_path
|
30
20
|
end
|
31
21
|
|
32
22
|
private
|
33
23
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# when 180
|
41
|
-
# return 180
|
42
|
-
# when 270
|
43
|
-
# return 0
|
44
|
-
# end
|
45
|
-
# end
|
24
|
+
def determine_thumb_dimension_ratio_from_uploaded_video(size)
|
25
|
+
video = MiniExiftool.new(current_path)
|
26
|
+
orientation = video.rotation
|
27
|
+
image_width, image_height = video_dimension(orientation, video.imagewidth, video.imageheight, size)
|
28
|
+
return "#{image_width.to_i}" + 'x' + "#{image_height.to_i}"
|
29
|
+
end
|
46
30
|
|
47
|
-
def video_dimension
|
31
|
+
def video_dimension(orientation, video_width, video_height, size)
|
48
32
|
case orientation
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
image_width = size
|
55
|
-
ratio = size.to_f/video_height
|
56
|
-
image_height = video_width * ratio
|
33
|
+
when 0, 180
|
34
|
+
image_width, image_height = find_width_and_height_of_landscape_video(video_width, video_height, size)
|
35
|
+
else
|
36
|
+
image_width, image_height = find_width_and_height_of_portrait_video(video_width, video_height, size)
|
57
37
|
end
|
58
38
|
return image_width, image_height
|
59
39
|
end
|
60
40
|
|
61
|
-
def
|
41
|
+
def find_width_and_height_of_portrait_video(video_width, video_height, size)
|
42
|
+
ratio = size.to_f/video_height
|
43
|
+
image_width = size
|
44
|
+
image_height = video_width * ratio
|
45
|
+
return image_width, image_height
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_width_and_height_of_landscape_video(video_width, video_height, size)
|
49
|
+
ratio = size.to_f/video_width
|
50
|
+
image_width = size
|
51
|
+
image_height = video_height * ratio
|
52
|
+
return image_width, image_height
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_temp_file(file_extension)
|
56
|
+
File.join(File.dirname(current_path), "tmpfile.#{file_extension}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def generate_command_for_thumbnail(options, temp_file_path)
|
60
|
+
thumbnail = GenerateCommand.new(current_path, temp_file_path)
|
61
|
+
return thumbnail.generate_command(options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_logs(command)
|
65
|
+
logger = Miniatura::Logger.new.logger
|
66
|
+
logger.info("Running command: #{command}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def execute_command(command)
|
70
|
+
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
71
|
+
@error = stderr.read
|
72
|
+
@exit_code = wait_thr.value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def handle_exit_code(exit_code, error)
|
77
|
+
logger = Miniatura::Logger.new.logger
|
62
78
|
if exit_code == 0
|
63
|
-
logger.info
|
79
|
+
logger.info 'Success!'
|
64
80
|
else
|
65
81
|
logger.error "Failure due to following error: #{error}"
|
66
82
|
end
|
67
|
-
exit_code
|
68
83
|
end
|
69
84
|
end
|
@@ -9,7 +9,7 @@ module Miniatura
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Generates ffmpeg command to create the thumbnail.
|
12
|
-
def generate_command
|
12
|
+
def generate_command(options = {})
|
13
13
|
options = Miniatura::Options.new(options)
|
14
14
|
%Q(ffmpeg #{options.to_options} #{output_path} -i #{input_path})
|
15
15
|
end
|
data/lib/miniatura/logger.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
module Miniatura
|
2
|
-
|
3
|
-
|
2
|
+
class Logger
|
3
|
+
attr_reader :logger
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@logger = Logger.new(STDOUT)
|
10
|
-
@logger.level = Logger::INFO
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
5
|
+
def initialize
|
6
|
+
@logger = Rails.logger
|
7
|
+
end
|
8
|
+
end
|
14
9
|
end
|
data/lib/miniatura/options.rb
CHANGED
@@ -1,42 +1,45 @@
|
|
1
1
|
module Miniatura
|
2
2
|
class Options
|
3
|
-
#Options class to add various options to the ffmpeg command
|
3
|
+
#Options class to add various options to the ffmpeg command generated.
|
4
4
|
|
5
5
|
CLI_KEY = {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
size: '-s',
|
7
|
+
time_frame: '-ss',
|
8
|
+
quality: '-q',
|
9
|
+
file_extension: '-c'
|
10
10
|
}
|
11
11
|
|
12
|
-
def initialize
|
13
|
-
@
|
12
|
+
def initialize(options)
|
13
|
+
@options = options
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_options
|
17
|
-
result = @
|
18
|
-
|
19
|
-
end
|
20
|
-
result << "-vframes 1"
|
17
|
+
result = @options.map { |k, v| send(k.to_s, v) }
|
18
|
+
result << '-vframes 1'
|
21
19
|
result.join(' ')
|
22
20
|
end
|
23
21
|
|
24
|
-
def file_extension
|
22
|
+
def file_extension(value)
|
25
23
|
case value
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
when 'jpeg'
|
25
|
+
'-c mjpeg'
|
26
|
+
when 'png'
|
27
|
+
'-c png'
|
28
|
+
else
|
29
|
+
''
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def rotate
|
33
|
+
def rotate(value)
|
34
34
|
case value
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
when 90
|
36
|
+
'-vf transpose=1'
|
37
|
+
when 180
|
38
|
+
'-vf hflip '
|
39
|
+
when 270
|
40
|
+
'-vf transpose=2'
|
41
|
+
else
|
42
|
+
''
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
data/lib/miniatura/version.rb
CHANGED
data/miniatura-0.5.0.gem
ADDED
Binary file
|
data/miniatura.gemspec
CHANGED
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'miniatura/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'miniatura'
|
8
8
|
spec.version = Miniatura::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['ssooraj']
|
10
|
+
spec.email = ['ssooraj7@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.license =
|
12
|
+
spec.summary = 'Carrierwave Video Thumbnailer.'
|
13
|
+
spec.description = 'Generates a thumbnail for carrierwave uploaded videos.'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split("\n")
|
17
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'exe'
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.2.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 13.0.3'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.10.0'
|
24
|
+
spec.add_development_dependency 'carrierwave-video', '~> 0.6.0'
|
25
|
+
spec.add_development_dependency 'mini_exiftool', '~> 2.10.0'
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miniatura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ssooraj
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.7
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 13.0.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 13.0.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.10.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.10.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: carrierwave-video
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.6.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.6.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mini_exiftool
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.10.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.10.0
|
83
83
|
description: Generates a thumbnail for carrierwave uploaded videos.
|
84
84
|
email:
|
85
85
|
- ssooraj7@gmail.com
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/miniatura/logger.rb
|
103
103
|
- lib/miniatura/options.rb
|
104
104
|
- lib/miniatura/version.rb
|
105
|
+
- miniatura-0.5.0.gem
|
105
106
|
- miniatura.gemspec
|
106
107
|
- spec/lib/generate_command_spec.rb
|
107
108
|
- spec/lib/miniatura_spec.rb
|
@@ -126,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
127
|
- !ruby/object:Gem::Version
|
127
128
|
version: '0'
|
128
129
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.5.2
|
130
|
+
rubygems_version: 3.2.3
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Carrierwave Video Thumbnailer.
|