active_analysis 0.1.3 → 0.2.0

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
  SHA256:
3
- metadata.gz: 682b39ef90eab2d2f825bb31f75b2345e32a4df0858d063f1f13314fd1aa25e6
4
- data.tar.gz: c5cb58d2b1ac0304fc220953b4cf7250e4568642b1be30017bf56caf71b2fea1
3
+ metadata.gz: 44cf23f9065e97caa7532489c6aa8f2ad0eb14c8cd9a6bfa5c632fbcb83b90cf
4
+ data.tar.gz: 84402156bf4c055d70ef121692cc0e0ac415a5d0cfa6ed91be31bacb410e7a4a
5
5
  SHA512:
6
- metadata.gz: '0860684f890ee8b3c1818ef547126de464c1b3a2434e70850dbcd3d57fddb087c478412753936a58608700564197bdaff7ed0951fceba4b6a4bb6b2eb0ad0135'
7
- data.tar.gz: f1eba05f7f54af13851000862d7c45d99e04a44ce511dfe2e815b2a1539df5f64a10df1d812a98fbbeb6f10c350dd3354f1c870c993e92754ed6326b415d6830
6
+ metadata.gz: ab5fcbe11d109a5e772522cd7f02d1482ca847b3b2b0aad5f005c0db46eee2b37811a689bf0b93131e7cb5910b7f1848f7179b054fc596ec4b2665d5baa1cad6
7
+ data.tar.gz: f7d992056c9bb40ec9dca2bb6d4816695c6c24fc9413eb10266cbe3db266abfa12866deeb3d4178c2dad6e21209ec8dac766fb204514fde19e939adbc4df88b8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2021-05-01
3
+ ## [0.2] - 2021-05-01
4
+
5
+ - Added `opaque` metadata value to images
6
+
7
+ ## [0.1.3] - 2021-05-01
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -18,11 +18,50 @@ And then execute:
18
18
 
19
19
  ## Usage
20
20
 
21
- Active Analyzers will automatically add all its analyzers to Active Storage's analyzers array. Don't worry, if you added any custom analyzers they will be there. You can check the comments in the source code of each analyzer to see what information they extract from files:
22
- - Audio: [source](https://github.com/FestaLab/active_analysis/blob/main/lib/active_analysis/analyzer/audio_analyzer.rb)
23
- - Image: [source](https://github.com/FestaLab/active_analysis/blob/main/lib/active_analysis/analyzer/image_analyzer.rb)
24
- - PDF: [source](https://github.com/FestaLab/active_analysis/blob/main/lib/active_analysis/analyzer/pdf_analyzer.rb)
25
- - Video: [source](https://github.com/FestaLab/active_analysis/blob/main/lib/active_analysis/analyzer/video_analyzer.rb)
21
+ Active Analysis automatically replaces all of Rails default analyzers with its own. It will not remove other custom analyzers if you have them. You can also configure which analyzers will be inserted.
22
+
23
+ ```ruby
24
+ Rails.application.configure do |config|
25
+ config.active_analysis.image_library = :vips # Defaults to the same as active storage
26
+ config.active_analysis.image_analyzer = true # Defaults to true
27
+ config.active_analysis.audio_analyzer = true # Defaults to true
28
+ config.active_analysis.pdf_analyzer = false # Defaults to true
29
+ config.active_analysis.video_analyzer = false # Defaults to true
30
+ end
31
+ ```
32
+
33
+ #### Image
34
+ A modification of the original image analyzer and a new analyzer. Requires the [ImageMagick](http://www.imagemagick.org) system library or the [libvips](https://github.com/libvips/libvips) system library.
35
+
36
+ - Width (pixels)
37
+ - Height (pixels)
38
+ - Opaque (true if file is opaque, false if not)
39
+
40
+ An image will be considered opaque if it does not have an alpha channel, or if none of its pixels have an alpha value below the minimum (as defined by the library).
41
+
42
+ #### PDF
43
+ A new analyzer. Requires the [poppler](https://poppler.freedesktop.org/) system library.
44
+
45
+ - Width (pixels)
46
+ - Height (pixels)
47
+ - Pages
48
+
49
+ #### Audio
50
+ A new analyzer. Requires the [FFmpeg](https://www.ffmpeg.org) system library.
51
+
52
+ - Duration (seconds)
53
+ - Bit Rate (bits/second)
54
+
55
+ #### Video
56
+ A modification of the original video analyzer. Requires the [FFmpeg](https://www.ffmpeg.org) system library
57
+
58
+ - Width (pixels)
59
+ - Height (pixels)
60
+ - Duration (seconds)
61
+ - Angle (degrees)
62
+ - Display aspect ratio
63
+ - Audio (true if file has an audio channel, false if not)
64
+ - Video (true if file has an video channel, false if not)
26
65
 
27
66
  ## Development
28
67
 
@@ -7,6 +7,9 @@ module ActiveAnalysis
7
7
  autoload :FixtureSet
8
8
 
9
9
  mattr_accessor :logger
10
- mattr_accessor :analyzers
11
10
  mattr_accessor :image_library
11
+ mattr_accessor :image_analyzer
12
+ mattr_accessor :audio_analyzer
13
+ mattr_accessor :pdf_analyzer
14
+ mattr_accessor :video_analyzer
12
15
  end
@@ -9,7 +9,7 @@ module ActiveAnalysis
9
9
  #
10
10
  # Example:
11
11
  #
12
- # ActiveAnalysis::CoreExtensionsAnalyzer::ImageAnalyzer::ImageMagick.new(blob).metadata
12
+ # ActiveAnalysis::Analyzer::ImageAnalyzer::ImageMagick.new(blob).metadata
13
13
  # # => { width: 4104, height: 2736 }
14
14
  class Analyzer::ImageAnalyzer < Analyzer
15
15
  def self.accept?(blob)
@@ -19,12 +19,25 @@ module ActiveAnalysis
19
19
  def metadata
20
20
  read_image do |image|
21
21
  if rotated_image?(image)
22
- { width: image.height, height: image.width }
22
+ { width: image.height, height: image.width, opaque: opaque?(image) }
23
23
  else
24
- { width: image.width, height: image.height }
24
+ { width: image.width, height: image.height, opaque: opaque?(image) }
25
25
  end
26
26
  end
27
27
  end
28
+
29
+ private
30
+ def read_image
31
+ raise NotImplementedError
32
+ end
33
+
34
+ def rotated_image?(image)
35
+ raise NotImplementedError
36
+ end
37
+
38
+ def opaque?(image)
39
+ raise NotImplementedError
40
+ end
28
41
  end
29
42
  end
30
43
 
@@ -7,7 +7,7 @@ module ActiveAnalysis
7
7
  # the {ImageMagick}[http://www.imagemagick.org] system library.
8
8
  class Analyzer::ImageAnalyzer::ImageMagick < Analyzer::ImageAnalyzer
9
9
  def self.accept?(blob)
10
- super && ActiveStorage.variant_processor == :mini_magick
10
+ super && ActiveAnalysis.image_library == :mini_magick
11
11
  end
12
12
 
13
13
  private
@@ -34,6 +34,13 @@ module ActiveAnalysis
34
34
  def rotated_image?(image)
35
35
  %w[ RightTop LeftBottom TopRight BottomLeft ].include?(image["%[orientation]"])
36
36
  end
37
+
38
+ def opaque?(image)
39
+ return true unless image.data["channelDepth"].key?("alpha")
40
+
41
+ value = image.data["version"] =~ /7.\d/ ? 255 : 0
42
+ image.data["channelStatistics"]["alpha"]["min"] == value
43
+ end
37
44
  end
38
45
  end
39
46
 
@@ -7,14 +7,14 @@ module ActiveAnalysis
7
7
  # the {libvips}[https://libvips.github.io/libvips/] system library.
8
8
  class Analyzer::ImageAnalyzer::Vips < Analyzer::ImageAnalyzer
9
9
  def self.accept?(blob)
10
- super && ActiveStorage.variant_processor == :vips
10
+ super && ActiveAnalysis.image_library == :vips
11
11
  end
12
12
 
13
13
  private
14
14
  def read_image
15
15
  download_blob_to_tempfile do |file|
16
16
  require "ruby-vips"
17
- image = ::Vips::Image.new_from_file(file.path, access: :sequential)
17
+ image = ::Vips::Image.new_from_file(file.path)
18
18
 
19
19
  if valid_image?(image)
20
20
  yield image
@@ -39,6 +39,11 @@ module ActiveAnalysis
39
39
  false
40
40
  end
41
41
 
42
+ def opaque?(image)
43
+ return true unless image.has_alpha?
44
+ image[image.bands - 1].min == 255
45
+ end
46
+
42
47
  def valid_image?(image)
43
48
  image.avg
44
49
  true
@@ -47,4 +52,3 @@ module ActiveAnalysis
47
52
  end
48
53
  end
49
54
  end
50
-
@@ -7,7 +7,7 @@ module ActiveAnalysis
7
7
  #
8
8
  # Example:
9
9
  #
10
- # ActiveAnalysis::CoreExtensionsAnalyzer::PDFAnalyzer::Poppler.new(blob).metadata
10
+ # ActiveAnalysis::Analyzer::PDFAnalyzer::Poppler.new(blob).metadata
11
11
  # # => { width: 4104, height: 2736, pages: 10 }
12
12
  #
13
13
  # This analyzer requires the {poppler}[https://poppler.freedesktop.org/] system library, which is not provided by Rails.
@@ -18,27 +18,41 @@ module ActiveAnalysis
18
18
  class Engine < ::Rails::Engine
19
19
  isolate_namespace ActiveAnalysis
20
20
 
21
- config.active_analysis = ActiveSupport::OrderedOptions.new
21
+ config.active_analysis = ActiveSupport::OrderedOptions.new
22
22
  config.eager_load_namespaces << ActiveAnalysis
23
23
 
24
24
  initializer "active_analysis.configs" do
25
25
  config.after_initialize do |app|
26
- ActiveAnalysis.logger = app.config.active_analysis.logger || Rails.logger
27
- ActiveAnalysis.analyzers = app.config.active_analysis.analyzers || []
28
- ActiveAnalysis.image_library = app.config.active_analysis.image_library || app.config.active_storage.variant_processor
26
+ ActiveAnalysis.logger = app.config.active_analysis.logger || Rails.logger
27
+ ActiveAnalysis.image_library = app.config.active_analysis.image_library || app.config.active_storage.variant_processor
28
+ ActiveAnalysis.image_analyzer = app.config.active_analysis.image_analyzer || true
29
+ ActiveAnalysis.audio_analyzer = app.config.active_analysis.audio_analyzer || true
30
+ ActiveAnalysis.pdf_analyzer = app.config.active_analysis.pdf_analyzer || true
31
+ ActiveAnalysis.video_analyzer = app.config.active_analysis.video_analyzer || true
29
32
  end
30
33
  end
31
34
 
32
- initializer "active_analysis.core_extensions" do
35
+ initializer "active_analysis.analyzers" do
33
36
  config.after_initialize do |app|
34
- app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer
35
- app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::VideoAnalyzer
36
-
37
- app.config.active_storage.analyzers.append Analyzer::ImageAnalyzer::Vips
38
- app.config.active_storage.analyzers.append Analyzer::ImageAnalyzer::ImageMagick
39
- app.config.active_storage.analyzers.append Analyzer::VideoAnalyzer
40
- app.config.active_storage.analyzers.append Analyzer::AudioAnalyzer
41
- app.config.active_storage.analyzers.append Analyzer::PDFAnalyzer
37
+ if ActiveAnalysis.image_analyzer
38
+ app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer
39
+ app.config.active_storage.analyzers.append Analyzer::ImageAnalyzer::Vips
40
+ app.config.active_storage.analyzers.append Analyzer::ImageAnalyzer::ImageMagick
41
+ end
42
+
43
+ if ActiveAnalysis.video_analyzer
44
+ app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::VideoAnalyzer
45
+ app.config.active_storage.analyzers.append Analyzer::VideoAnalyzer
46
+ end
47
+
48
+ if ActiveAnalysis.audio_analyzer
49
+ app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer if defined?(ActiveStorage::Analyzer::ImageAnalyzer)
50
+ app.config.active_storage.analyzers.append Analyzer::AudioAnalyzer
51
+ end
52
+
53
+ if ActiveAnalysis.pdf_analyzer
54
+ app.config.active_storage.analyzers.append Analyzer::PDFAnalyzer
55
+ end
42
56
  end
43
57
  end
44
58
  end
@@ -8,8 +8,8 @@ module ActiveAnalysis
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 0
11
- MINOR = 1
12
- TINY = 3
11
+ MINOR = 2
12
+ TINY = 0
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Breno Gazzola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-11 00:00:00.000000000 Z
11
+ date: 2021-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '6.0'
20
20
  type: :runtime
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: '6.1'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '6.1'
33
+ version: '6.0'
34
34
  type: :runtime
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: '6.1'
40
+ version: '6.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mini_magick
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.0.3
222
+ rubygems_version: 3.2.17
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: Collection of Active Storage analyzers