miniatura 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aebe9d9b53b477af6ced6fa88cb192c80d44e949
4
- data.tar.gz: f122166ef6ab98f459f2a15782e7f0865817a0d1
3
+ metadata.gz: 2ffe72fc7dd04b59bd7714bcc0aa44bd762f43a4
4
+ data.tar.gz: d4d1a4f3eb993e84612ca65a42a706125e8d9411
5
5
  SHA512:
6
- metadata.gz: 7def9c36609659c7b6f3a7fa7850739ae3d6ef427d8832e37b3e4f77a4cbd221ad5acbc446489c5be3ce0b8133a1ae447a104f6d9defc74c58de6b912176c085
7
- data.tar.gz: 1598d2901924eabdc6df743a9a49d1a14576820e7dd6a46cab86ba39e61c3c0b1086f7466dd64354ac6279cee926167f9f999fc668c402f869c966e721e61531
6
+ metadata.gz: c59cc152233270a136a9736d5827004c66e925651a614d69541992080c41ed66f5d7ce6ec9276be89ed7df7236b3384cbbf42da6d0d283a31158ff2f862c588f
7
+ data.tar.gz: 9130434bfeeabb619f0c8b56d63755a327f9a66f64d07638fedcf2db2c9c1b31421cbfaaf5bbb4dbb1b2eadb15316b332d89369c1f3909dd9af00ce78d94f8f0
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /.idea/
11
+ .idea/
@@ -9,7 +9,7 @@ module Miniatura
9
9
  end
10
10
 
11
11
  # Generates ffmpeg command to create the thumbnail.
12
- def generate_command options = {}
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
@@ -1,42 +1,47 @@
1
1
  module Miniatura
2
2
  class Options
3
- #Options class to add various options to the ffmpeg command genrated.
3
+ #Options class to add various options to the ffmpeg command generated.
4
4
 
5
5
  CLI_KEY = {
6
- size: '-s',
7
- time_frame: '-ss',
8
- quality: '-q',
9
- file_extension: '-c'
6
+ size: '-s',
7
+ time_frame: '-ss',
8
+ quality: '-q',
9
+ file_extension: '-c'
10
10
  }
11
11
 
12
- def initialize options
13
- @ptions = options
12
+ def initialize(options)
13
+ @options = options
14
14
  end
15
15
 
16
16
  def to_options
17
- result = @ptions.map do |k, v|
17
+ result = @options.map do |k, v|
18
18
  send(k.to_s, v)
19
19
  end
20
- result << "-vframes 1"
20
+ result << '-vframes 1'
21
21
  result.join(' ')
22
22
  end
23
23
 
24
- def file_extension value
24
+ def file_extension(value)
25
25
  case value
26
- when 'jpeg' then %Q(-c mjpeg)
27
- when 'png' then %Q(-c png)
28
- else
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 value
35
+ def rotate(value)
34
36
  case value
35
- when 90 then %Q(-vf transpose=1)
36
- when 180 then %Q(-vf hflip )
37
- when 270 then %Q(-vf transpose=2)
38
- else
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
 
@@ -1,3 +1,3 @@
1
1
  module Miniatura
2
- VERSION = "0.3.3"
2
+ VERSION = '0.3.4'
3
3
  end
data/lib/miniatura.rb CHANGED
@@ -1,20 +1,20 @@
1
- require "open3"
2
- require "miniatura/version"
3
- require "miniatura/options"
4
- require "miniatura/logger"
5
- require "miniatura/generate_command"
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 options = {}
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( File.dirname(current_path), "tmpfile.#{options[:file_extension]}")
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 = stderr.read
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
- # def video_rotation orientation
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
- when 0,180
50
- image_width = size
51
- ratio = size.to_f/video_width
52
- image_height = video_height * ratio
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 "Success!"
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 = "miniatura"
7
+ spec.name = 'miniatura'
8
8
  spec.version = Miniatura::VERSION
9
- spec.authors = ["ssooraj"]
10
- spec.email = ["ssooraj7@gmail.com"]
9
+ spec.authors = ['ssooraj']
10
+ spec.email = ['ssooraj7@gmail.com']
11
11
 
12
- spec.summary = "Carrierwave Video Thumbnailer."
13
- spec.description = "Generates a thumbnail for carrierwave uploaded videos."
14
- spec.license = "MIT"
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 = "exe"
17
+ spec.bindir = 'exe'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
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"
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.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: 2016-12-08 00:00:00.000000000 Z
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.5.2
130
+ rubygems_version: 2.6.8
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Carrierwave Video Thumbnailer.