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 +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +44 -5
- data/lib/active_analysis.rb +4 -1
- data/lib/active_analysis/analyzer/image_analyzer.rb +16 -3
- data/lib/active_analysis/analyzer/image_analyzer/image_magick.rb +8 -1
- data/lib/active_analysis/analyzer/image_analyzer/vips.rb +7 -3
- data/lib/active_analysis/analyzer/pdf_analyzer.rb +1 -1
- data/lib/active_analysis/engine.rb +27 -13
- data/lib/active_analysis/gem_version.rb +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44cf23f9065e97caa7532489c6aa8f2ad0eb14c8cd9a6bfa5c632fbcb83b90cf
|
4
|
+
data.tar.gz: 84402156bf4c055d70ef121692cc0e0ac415a5d0cfa6ed91be31bacb410e7a4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab5fcbe11d109a5e772522cd7f02d1482ca847b3b2b0aad5f005c0db46eee2b37811a689bf0b93131e7cb5910b7f1848f7179b054fc596ec4b2665d5baa1cad6
|
7
|
+
data.tar.gz: f7d992056c9bb40ec9dca2bb6d4816695c6c24fc9413eb10266cbe3db266abfa12866deeb3d4178c2dad6e21209ec8dac766fb204514fde19e939adbc4df88b8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -18,11 +18,50 @@ And then execute:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Active
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
|
data/lib/active_analysis.rb
CHANGED
@@ -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::
|
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 &&
|
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 &&
|
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
|
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::
|
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
|
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
|
27
|
-
ActiveAnalysis.
|
28
|
-
ActiveAnalysis.
|
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.
|
35
|
+
initializer "active_analysis.analyzers" do
|
33
36
|
config.after_initialize do |app|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
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.
|
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
|
+
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.
|
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.
|
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.
|
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.
|
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.
|
222
|
+
rubygems_version: 3.2.17
|
223
223
|
signing_key:
|
224
224
|
specification_version: 4
|
225
225
|
summary: Collection of Active Storage analyzers
|