active_analysis 0.3.1 → 0.5.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 +15 -2
- data/README.md +1 -2
- data/app/controllers/active_analysis/application_controller.rb +2 -0
- data/app/helpers/active_analysis/application_helper.rb +2 -0
- data/app/jobs/active_analysis/application_job.rb +2 -0
- data/app/mailers/active_analysis/application_mailer.rb +4 -2
- data/app/models/active_analysis/application_record.rb +2 -0
- data/config/routes.rb +2 -0
- data/lib/active_analysis.rb +2 -0
- data/lib/active_analysis/addon/image_addon.rb +3 -3
- data/lib/active_analysis/addon/image_addon/white_background.rb +0 -1
- data/lib/active_analysis/analyzer/audio_analyzer.rb +0 -1
- data/lib/active_analysis/analyzer/image_analyzer.rb +0 -1
- data/lib/active_analysis/analyzer/image_analyzer/image_magick.rb +1 -2
- data/lib/active_analysis/engine.rb +4 -2
- data/lib/active_analysis/gem_version.rb +2 -2
- data/lib/tasks/active_analysis_tasks.rake +1 -0
- metadata +2 -3
- data/lib/active_analysis/addon/image_addon/optimal_quality.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77a4b728e66fe4c463fabcdc68c89ab4d6b73971aec95f96ea0bf29fc944c866
|
4
|
+
data.tar.gz: cc74b804d1c0ca9c803027fe2427ad99cbcc1cf1764c691865f4f092acc682d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6e6fe01cf6c05e6fbe3fa36fa7f1df96dfeb395566b1612b01da8105abe9546d5f994064cc7924c6cc8d076084f5d7bd2750f4662f670070214faf9781441f9
|
7
|
+
data.tar.gz: 3106253d44f736d2640c63bcb4bea1a04d4654d39d3e88f6ac3ebebf12c6848238f65f481e94511a69af74eed506a9b8a69c9c9e7a44963cdb775418ebb66830
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
|
3
|
+
- Make it easier to override target dssim and minimum quality in the optimal quality addon
|
4
|
+
|
5
|
+
## [0.4.0] - 2021-06-22
|
6
|
+
|
7
|
+
- Remove the new Rails analyzers
|
8
|
+
- Do not detect optimal quality of variants
|
9
|
+
- Start optimal quality calculation at quality = 75 to match Vitals Image quality = 80
|
10
|
+
- Fix Rubocop offenses
|
11
|
+
|
12
|
+
## [0.3.1] - 2021-06-17
|
13
|
+
|
14
|
+
- Fix vips image path call
|
15
|
+
|
16
|
+
## [0.3.0] - 2021-06-17
|
4
17
|
|
5
18
|
- Added addons feature
|
6
19
|
|
7
|
-
## [0.2] - 2021-06-01
|
20
|
+
## [0.2.0] - 2021-06-01
|
8
21
|
|
9
22
|
- Added `opaque` metadata value to images
|
10
23
|
|
data/README.md
CHANGED
@@ -67,12 +67,11 @@ A modification of the original video analyzer. Requires the [FFmpeg](https://www
|
|
67
67
|
Active Analysis allows additional features to be added to the image analyzers through addons. To create an addon simply inherit the `Addon` class and add it to the addons array in the configuration.
|
68
68
|
```ruby
|
69
69
|
Rails.application.configure do |config|
|
70
|
-
config.active_analysis.addons << ActiveAnalysis::Addon::ImageAddon::
|
70
|
+
config.active_analysis.addons << ActiveAnalysis::Addon::ImageAddon::WhiteBackground
|
71
71
|
end
|
72
72
|
```
|
73
73
|
|
74
74
|
The following addons available:
|
75
|
-
- ImageAddon::OptimalQuality: An EXPERIMENTAL addon that calculates the optimal image quality using a DSSIM of 0.001. This addon is SLOOOOOOW.
|
76
75
|
- ImageAddon::WhiteBackground: An EXPERIMENTAL addon that checks if the image has a white background. Requires both vips and image magick to be installed.
|
77
76
|
|
78
77
|
## Development
|
data/config/routes.rb
CHANGED
data/lib/active_analysis.rb
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
require_relative "../addon"
|
4
4
|
|
5
5
|
module ActiveAnalysis
|
6
|
-
# This is an abstract base class for image addons
|
6
|
+
# This is an abstract base class for image addons. Image addons are only executed for original
|
7
|
+
# blobs.
|
7
8
|
class Addon::ImageAddon < Addon
|
8
9
|
def self.accept?(blob)
|
9
|
-
blob.image?
|
10
|
+
blob.image? && blob.attachments.none? { |attachment| attachment.record_type == ActiveStorage::VariantRecord }
|
10
11
|
end
|
11
12
|
|
12
13
|
def metadata
|
@@ -14,4 +15,3 @@ module ActiveAnalysis
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
@@ -38,9 +38,8 @@ module ActiveAnalysis
|
|
38
38
|
def opaque?(image)
|
39
39
|
return true unless image.data["channelDepth"].key?("alpha")
|
40
40
|
|
41
|
-
value = image.data["version"]
|
41
|
+
value = /7.\d/.match?(image.data["version"]) ? 255 : 0
|
42
42
|
image.data["channelStatistics"]["alpha"]["mean"] == value
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
@@ -17,7 +17,6 @@ require_relative "analyzer/pdf_analyzer"
|
|
17
17
|
|
18
18
|
require_relative "addon"
|
19
19
|
require_relative "addon/image_addon"
|
20
|
-
require_relative "addon/image_addon/optimal_quality"
|
21
20
|
require_relative "addon/image_addon/white_background"
|
22
21
|
|
23
22
|
module ActiveAnalysis
|
@@ -46,6 +45,9 @@ module ActiveAnalysis
|
|
46
45
|
config.after_initialize do |app|
|
47
46
|
if ActiveAnalysis.image_analyzer
|
48
47
|
app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer
|
48
|
+
app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer::Vips if defined?(ActiveStorage::Analyzer::ImageAnalyzer::Vips)
|
49
|
+
app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick if defined?(ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick)
|
50
|
+
|
49
51
|
app.config.active_storage.analyzers.append Analyzer::ImageAnalyzer::Vips
|
50
52
|
app.config.active_storage.analyzers.append Analyzer::ImageAnalyzer::ImageMagick
|
51
53
|
end
|
@@ -56,7 +58,7 @@ module ActiveAnalysis
|
|
56
58
|
end
|
57
59
|
|
58
60
|
if ActiveAnalysis.audio_analyzer
|
59
|
-
app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::
|
61
|
+
app.config.active_storage.analyzers.delete ActiveStorage::Analyzer::AudioAnalyzer if defined?(ActiveStorage::Analyzer::AudioAnalyzer)
|
60
62
|
app.config.active_storage.analyzers.append Analyzer::AudioAnalyzer
|
61
63
|
end
|
62
64
|
|
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.5.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-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|
@@ -159,7 +159,6 @@ files:
|
|
159
159
|
- lib/active_analysis.rb
|
160
160
|
- lib/active_analysis/addon.rb
|
161
161
|
- lib/active_analysis/addon/image_addon.rb
|
162
|
-
- lib/active_analysis/addon/image_addon/optimal_quality.rb
|
163
162
|
- lib/active_analysis/addon/image_addon/white_background.rb
|
164
163
|
- lib/active_analysis/analyzer.rb
|
165
164
|
- lib/active_analysis/analyzer/audio_analyzer.rb
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../image_addon"
|
4
|
-
|
5
|
-
module ActiveAnalysis
|
6
|
-
class Addon::ImageAddon::OptimalQuality < Addon::ImageAddon
|
7
|
-
def metadata
|
8
|
-
{ optimal_quality: calculate_optimal_quality }
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
def calculate_optimal_quality
|
13
|
-
quality = 85
|
14
|
-
|
15
|
-
loop do
|
16
|
-
new_quality = quality - 5
|
17
|
-
dssim = calculate_dssim(new_quality)
|
18
|
-
break if dssim > 0.001 || quality < 55
|
19
|
-
quality = new_quality
|
20
|
-
end
|
21
|
-
|
22
|
-
quality
|
23
|
-
rescue
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def calculate_dssim(quality)
|
28
|
-
image_with_quality(quality) do |image|
|
29
|
-
dssim = `dssim #{filepath} #{image.path}`
|
30
|
-
Float dssim.split.first
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def image_with_quality(quality)
|
35
|
-
extname = File.extname(filepath)
|
36
|
-
basename = File.basename(filepath, extname)
|
37
|
-
|
38
|
-
Tempfile.create(["#{basename}_#{quality}", extname]) do |tempfile|
|
39
|
-
processor.apply(saver: { format: "jpg", quality: quality }).call(filepath, destination: tempfile.path)
|
40
|
-
yield tempfile
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def filepath
|
45
|
-
ActiveAnalysis.image_library == :vips ? file.filename : file.path
|
46
|
-
end
|
47
|
-
|
48
|
-
def processor
|
49
|
-
ActiveAnalysis.image_library == :vips ? ::ImageProcessing::Vips : ::ImageProcessing::MiniMagick
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|