miniatura 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/lib/miniatura/generate_command.rb +1 -1
- data/lib/miniatura/options.rb +25 -20
- data/lib/miniatura/version.rb +1 -1
- data/lib/miniatura.rb +29 -32
- data/miniatura.gemspec +13 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ffe72fc7dd04b59bd7714bcc0aa44bd762f43a4
|
4
|
+
data.tar.gz: d4d1a4f3eb993e84612ca65a42a706125e8d9411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c59cc152233270a136a9736d5827004c66e925651a614d69541992080c41ed66f5d7ce6ec9276be89ed7df7236b3384cbbf42da6d0d283a31158ff2f862c588f
|
7
|
+
data.tar.gz: 9130434bfeeabb619f0c8b56d63755a327f9a66f64d07638fedcf2db2c9c1b31421cbfaaf5bbb4dbb1b2eadb15316b332d89369c1f3909dd9af00ce78d94f8f0
|
data/.gitignore
CHANGED
@@ -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/options.rb
CHANGED
@@ -1,42 +1,47 @@
|
|
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 = @
|
17
|
+
result = @options.map do |k, v|
|
18
18
|
send(k.to_s, v)
|
19
19
|
end
|
20
|
-
result <<
|
20
|
+
result << '-vframes 1'
|
21
21
|
result.join(' ')
|
22
22
|
end
|
23
23
|
|
24
|
-
def file_extension
|
24
|
+
def file_extension(value)
|
25
25
|
case value
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
when 'jpeg' then
|
27
|
+
'-c mjpeg'
|
28
|
+
when 'png' then
|
29
|
+
'-c png'
|
30
|
+
else
|
31
|
+
''
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def rotate
|
35
|
+
def rotate(value)
|
34
36
|
case value
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
when 90 then
|
38
|
+
'-vf transpose=1'
|
39
|
+
when 180 then
|
40
|
+
'-vf hflip '
|
41
|
+
when 270 then
|
42
|
+
'-vf transpose=2'
|
43
|
+
else
|
44
|
+
''
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
data/lib/miniatura/version.rb
CHANGED
data/lib/miniatura.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
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
9
|
options[:file_extension] ||= 'jpeg'
|
10
10
|
options[:logger] = Rails.logger
|
11
11
|
size = options[:size]
|
12
|
+
options[:rotate] = 0
|
12
13
|
video = MiniExiftool.new(current_path)
|
13
14
|
orientation = video.rotation
|
14
|
-
options[:rotate] = 0
|
15
15
|
image_width, image_height = video_dimension(orientation, video.imagewidth, video.imageheight, size)
|
16
16
|
options[:size] = "#{image_width.to_i}" + "x" + "#{image_height.to_i}"
|
17
|
-
tmp_path = File.join(
|
17
|
+
tmp_path = File.join(File.dirname(current_path), "tmpfile.#{options[:file_extension]}")
|
18
18
|
thumbnail = GenerateCommand.new(current_path, tmp_path)
|
19
19
|
cmd = thumbnail.generate_command(options)
|
20
20
|
logger = Miniatura::Logger.new(options).logger
|
@@ -22,7 +22,7 @@ module Miniatura
|
|
22
22
|
exit_code, error = nil
|
23
23
|
raise Errno::ENOENT unless File.exist?(current_path)
|
24
24
|
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
25
|
-
error =
|
25
|
+
error = stderr.read
|
26
26
|
exit_code = wait_thr.value
|
27
27
|
end
|
28
28
|
handle_exit_code(exit_code, error, logger)
|
@@ -31,36 +31,33 @@ module Miniatura
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
|
35
|
-
# case orientation
|
36
|
-
# when 0
|
37
|
-
# return 0
|
38
|
-
# when 90
|
39
|
-
# return 0
|
40
|
-
# when 180
|
41
|
-
# return 180
|
42
|
-
# when 270
|
43
|
-
# return 0
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
|
47
|
-
def video_dimension orientation, video_width, video_height, size
|
34
|
+
def video_dimension(orientation, video_width, video_height, size)
|
48
35
|
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
|
36
|
+
when 0, 180
|
37
|
+
image_width, image_height = find_width_and_height_of_landscape_video(video_width, video_height, size)
|
38
|
+
else
|
39
|
+
image_width, image_height = find_width_and_height_of_portrait_video(video_width, video_height, size)
|
57
40
|
end
|
58
41
|
return image_width, image_height
|
59
42
|
end
|
60
43
|
|
44
|
+
def find_width_and_height_of_portrait_video(video_width, video_height, size)
|
45
|
+
ratio = size.to_f/video_height
|
46
|
+
image_width = size
|
47
|
+
image_height = video_width * ratio
|
48
|
+
return image_width, image_height
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_width_and_height_of_landscape_video(video_width, video_height, size)
|
52
|
+
ratio = size.to_f/video_width
|
53
|
+
image_width = size
|
54
|
+
image_height = video_height * ratio
|
55
|
+
return image_width, image_height
|
56
|
+
end
|
57
|
+
|
61
58
|
def handle_exit_code(exit_code, error, logger)
|
62
59
|
if exit_code == 0
|
63
|
-
logger.info
|
60
|
+
logger.info 'Success!'
|
64
61
|
else
|
65
62
|
logger.error "Failure due to following error: #{error}"
|
66
63
|
end
|
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', '~> 1.13'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.5'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
24
|
+
spec.add_development_dependency 'carrierwave-video', '~> 0.5.6'
|
25
|
+
spec.add_development_dependency 'mini_exiftool', '~> 2.8'
|
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.3.
|
4
|
+
version: 0.3.4
|
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: 2017-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.6.8
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Carrierwave Video Thumbnailer.
|