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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9bd54c9d6b6579f5419244bdce0170c10889efc633d363b2a9be8129335b0bf
4
- data.tar.gz: bea8aa7a1e0f5c8d716c6d9eb2c3d253f5a1be3cb461484c16b5e281f47cd6bd
3
+ metadata.gz: 77a4b728e66fe4c463fabcdc68c89ab4d6b73971aec95f96ea0bf29fc944c866
4
+ data.tar.gz: cc74b804d1c0ca9c803027fe2427ad99cbcc1cf1764c691865f4f092acc682d1
5
5
  SHA512:
6
- metadata.gz: 402b15df181ac8bc2f583e70d9f856d7b7a9271493883a5ee9b7998aa890cb15c771f68e5be12028b4bfca29bf2514886fd09d841106cba88bed50975067dedb
7
- data.tar.gz: f35aa5ac09d2f3294512541733f38d5fa649c82994c685d26d92f9dd94f6f6e15a83fda66affae7553b7028fb1878542586242d524124f8afa6a8d226052e52a
6
+ metadata.gz: d6e6fe01cf6c05e6fbe3fa36fa7f1df96dfeb395566b1612b01da8105abe9546d5f994064cc7924c6cc8d076084f5d7bd2750f4662f670070214faf9781441f9
7
+ data.tar.gz: 3106253d44f736d2640c63bcb4bea1a04d4654d39d3e88f6ac3ebebf12c6848238f65f481e94511a69af74eed506a9b8a69c9c9e7a44963cdb775418ebb66830
data/CHANGELOG.md CHANGED
@@ -1,10 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.3] - 2021-06-17
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::OptimalQuality
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveAnalysis
2
4
  class ApplicationController < ActionController::Base
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveAnalysis
2
4
  module ApplicationHelper
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveAnalysis
2
4
  class ApplicationJob < ActiveJob::Base
3
5
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveAnalysis
2
4
  class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
+ default from: "from@example.com"
6
+ layout "mailer"
5
7
  end
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveAnalysis
2
4
  class ApplicationRecord < ActiveRecord::Base
3
5
  self.abstract_class = true
data/config/routes.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveAnalysis::Engine.routes.draw do
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_analysis/version"
2
4
  require "active_analysis/engine"
3
5
 
@@ -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
-
@@ -60,4 +60,3 @@ module ActiveAnalysis
60
60
  end
61
61
  end
62
62
  end
63
-
@@ -63,4 +63,3 @@ module ActiveAnalysis
63
63
  end
64
64
  end
65
65
  end
66
-
@@ -44,4 +44,3 @@ module ActiveAnalysis
44
44
  end
45
45
  end
46
46
  end
47
-
@@ -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"] =~ /7.\d/ ? 255 : 0
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::ImageAnalyzer if defined?(ActiveStorage::Analyzer::ImageAnalyzer)
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
 
@@ -8,8 +8,8 @@ module ActiveAnalysis
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 0
11
- MINOR = 3
12
- TINY = 1
11
+ MINOR = 5
12
+ TINY = 0
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # desc "Explaining what the task does"
2
3
  # task :active_analysis do
3
4
  # # Task goes here
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.3.1
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-18 00:00:00.000000000 Z
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