vitals_image 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c75ba4087e4d7a4028c7264bb3aa2fe3a5084eb1f627714d58e468f3a999289
4
- data.tar.gz: 625fe4c2c4462b749b0c841e218461c7740e633e054a2f269b9b34f41b5fde04
3
+ metadata.gz: b9a6e4da54850851d9b8e5366d3e07053272e32393d821d120f223045fc298d9
4
+ data.tar.gz: 10353144a856a6f24cc830ea3087f24d390bbecf4c962f5600ab6592344aac84
5
5
  SHA512:
6
- metadata.gz: b8042b6efa3d6c6164a62a4ccc6b576a9993525f8efbbd8e19ad0a1fa7ac6d15d28c0e68e5604ae22823c6a39266747c3180f72350bce97889c3a3a228f8c02c
7
- data.tar.gz: fb2a462820d0228734fef483bee2beefefab5065556a8e916c37493c9ffe651c442b21cd193f82375b59e2c19b72bd702a9d91abc10c636fbcac90cc5f2f6904
6
+ metadata.gz: ba5154564de3e592ddb4cec088397e31e46418a14e2517b7da93496a70aed868c43249e78740bcddc9d73cce61f5b44a6e6bf6d74240b38bf10ebdb30522d70a
7
+ data.tar.gz: db3cc9c5230f55c626a92bc340eef681d7da0b7d7fc3ab47c263a805a88debca84395c7865e49a77b96bf44810000811bb204b4af8c5c02e11e1cbd2f97ea665
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2021-07-06
4
+
5
+ - Fixed resize and pad in vips
6
+ - Fixed image quality in vips
7
+ - Reduced JPEG quality from 85 to 80
8
+ - Removed optimal quality
9
+ - Updated Vitals Image to 0.5
10
+
11
+ ## [0.3.0] - 2021-05-22
12
+
13
+ - Redo the image helper
14
+ - Redo the active storage optimizer
15
+
3
16
  ## [0.2.1] - 2021-05-22
4
17
 
5
18
  - Do not attempt to transform invariable images
@@ -6,32 +6,17 @@ module VitalsImage
6
6
  source = image_url(source) if source.is_a?(String)
7
7
  optimizer = VitalsImage::Base.optimizer(source, options)
8
8
 
9
- if !optimizer.variable?
10
- vitals_image_invariable_tag(optimizer)
11
- elsif optimizer.native_lazy_load?
12
- vitals_image_variable_tag(optimizer)
13
- else
14
- vitals_image_lazy_tag(optimizer)
15
- end
16
- end
17
-
18
- private
19
- def vitals_image_invariable_tag(optimizer)
20
- image_tag optimizer.src, optimizer.html_options
21
- end
22
-
23
- def vitals_image_variable_tag(optimizer)
24
- url = vitals_image_url(optimizer.src, optimizer.html_options)
25
- image_tag url, optimizer.html_options
26
- end
27
-
28
- def vitals_image_lazy_tag(optimizer)
9
+ if optimizer.non_native_lazy_load?
29
10
  url = vitals_image_url(optimizer.html_options["data"]["src"], optimizer.html_options)
30
11
  optimizer.html_options["data"]["src"] = url
31
-
32
12
  image_tag optimizer.src, optimizer.html_options
13
+ else
14
+ url = vitals_image_url(optimizer.src, optimizer.html_options)
15
+ image_tag url, optimizer.html_options
33
16
  end
17
+ end
34
18
 
19
+ private
35
20
  def vitals_image_url(source, options)
36
21
  active_storage_route = options.delete("active_storage_route") || VitalsImage.active_storage_route
37
22
 
@@ -19,14 +19,15 @@ require "vitals_image/errors"
19
19
  require "vitals_image/optimizer"
20
20
  require "vitals_image/optimizer/blank"
21
21
  require "vitals_image/optimizer/url"
22
- require "vitals_image/optimizer/active_storage"
22
+ require "vitals_image/optimizer/variable"
23
+ require "vitals_image/optimizer/invariable"
23
24
 
24
25
  module VitalsImage
25
26
  class Engine < ::Rails::Engine
26
27
  isolate_namespace VitalsImage
27
28
 
28
29
  config.vitals_image = ActiveSupport::OrderedOptions.new
29
- config.vitals_image.optimizers = [VitalsImage::Optimizer::Blank, VitalsImage::Optimizer::ActiveStorage, VitalsImage::Optimizer::Url]
30
+ config.vitals_image.optimizers = [VitalsImage::Optimizer::Blank, VitalsImage::Optimizer::Variable, VitalsImage::Optimizer::Invariable, VitalsImage::Optimizer::Url]
30
31
  config.vitals_image.analyzers = [VitalsImage::Analyzer::UrlAnalyzer]
31
32
 
32
33
  config.eager_load_namespaces << VitalsImage
@@ -69,13 +70,13 @@ module VitalsImage
69
70
  initializer "vitals_image.optimizations" do
70
71
  config.after_initialize do |app|
71
72
  if VitalsImage.image_library == :vips
72
- VitalsImage.jpeg_conversion ||= { saver: { strip: true, quality: 85, interlace: true, optimize_coding: true, trellis_quant: true, quant_table: 3, background: 255 }, format: "jpg" }
73
- VitalsImage.jpeg_optimization ||= { saver: { strip: true, quality: 85, interlace: true, optimize_coding: true, trellis_quant: true, quant_table: 3 } }
73
+ VitalsImage.jpeg_conversion ||= { saver: { strip: true, quality: 80, interlace: true, optimize_coding: true, trellis_quant: true, quant_table: 3, background: 255 }, format: "jpg" }
74
+ VitalsImage.jpeg_optimization ||= { saver: { strip: true, quality: 80, interlace: true, optimize_coding: true, trellis_quant: true, quant_table: 3 } }
74
75
  VitalsImage.png_optimization ||= { saver: { strip: true, compression: 9 } }
75
76
  else
76
- VitalsImage.jpeg_conversion ||= { saver: { strip: true, quality: 85, interlace: "JPEG", sampling_factor: "4:2:0", colorspace: "sRGB", background: :white, flatten: true, alpha: :off }, format: "jpg" }
77
- VitalsImage.jpeg_optimization ||= { saver: { strip: true, quality: 85, interlace: "JPEG", sampling_factor: "4:2:0", colorspace: "sRGB" } }
78
- VitalsImage.png_optimization ||= { saver: { strip: true, quality: 00 } }
77
+ VitalsImage.jpeg_conversion ||= { saver: { strip: true, quality: 80, interlace: "JPEG", sampling_factor: "4:2:0", colorspace: "sRGB", background: :white, flatten: true, alpha: :off }, format: "jpg" }
78
+ VitalsImage.jpeg_optimization ||= { saver: { strip: true, quality: 80, interlace: "JPEG", sampling_factor: "4:2:0", colorspace: "sRGB" } }
79
+ VitalsImage.png_optimization ||= { saver: { strip: true, quality: 75 } }
79
80
  end
80
81
  end
81
82
  end
@@ -8,8 +8,8 @@ module VitalsImage
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 0
11
- MINOR = 2
12
- TINY = 1
11
+ MINOR = 4
12
+ TINY = 0
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -26,7 +26,7 @@ module VitalsImage
26
26
 
27
27
  def html_options
28
28
  @html_options ||= begin
29
- html_options = @options.dup
29
+ html_options = @options.dup.except("lazy_load")
30
30
  html_options["width"] = width
31
31
  html_options["height"] = height
32
32
  html_options["style"] = style
@@ -57,11 +57,6 @@ module VitalsImage
57
57
  lazy_load? && VitalsImage.lazy_loading == :native
58
58
  end
59
59
 
60
- # Override this method in a concrete subclass. Have it return true the source is an active storage blob
61
- def variable?
62
- false
63
- end
64
-
65
60
  private
66
61
  def style
67
62
  if analyzed? && !requested_height
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VitalsImage
4
+ class Optimizer::Invariable < Optimizer
5
+ def self.accept?(source)
6
+ source.respond_to?(:variable?) && !source.variable?
7
+ end
8
+
9
+ private
10
+ def source_url
11
+ @source
12
+ end
13
+
14
+ def style
15
+ if !analyzed?
16
+ # Do nothing
17
+ elsif !requested_height
18
+ "height:auto;"
19
+ elsif fixed_dimensions?
20
+ "object-fit: contain;"
21
+ end
22
+ end
23
+
24
+ def original_width
25
+ metadata[:width]
26
+ end
27
+
28
+ def original_height
29
+ metadata[:height]
30
+ end
31
+
32
+ def metadata
33
+ @source.metadata
34
+ end
35
+
36
+ def analyzed?
37
+ metadata[:analyzed]
38
+ end
39
+ end
40
+ end
@@ -1,13 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VitalsImage
4
- class Optimizer::ActiveStorage < Optimizer
4
+ class Optimizer::Variable < Optimizer
5
5
  def self.accept?(source)
6
- source.is_a?(::ActiveStorage::Attached) || source.is_a?(::ActiveStorage::Attachment) || source.is_a?(::ActiveStorage::Blob)
7
- end
8
-
9
- def variable?
10
- @source.variable?
6
+ source.respond_to?(:variable?) && source.variable?
11
7
  end
12
8
 
13
9
  private
@@ -65,31 +61,31 @@ module VitalsImage
65
61
  end
66
62
 
67
63
  def optimize_jpeg
68
- @source.variant optimizations_with_optimal_quality(VitalsImage.jpeg_optimization)
64
+ @source.variant resize_and_flatten(VitalsImage.jpeg_optimization)
69
65
  end
70
66
 
71
67
  def optimize_png
72
68
  if alpha? || !VitalsImage.convert_to_jpeg
73
- @source.variant optimizations(VitalsImage.png_optimization)
69
+ @source.variant resize(VitalsImage.png_optimization)
74
70
  else
75
- @source.variant optimizations_with_optimal_quality(VitalsImage.jpeg_conversion)
71
+ @source.variant resize_and_flatten(VitalsImage.jpeg_conversion)
76
72
  end
77
73
  end
78
74
 
79
75
  def optimize_generic
80
76
  if alpha? || !VitalsImage.convert_to_jpeg
81
- @source.variant optimizations
77
+ @source.variant resize
82
78
  else
83
- @source.variant optimizations_with_optimal_quality(VitalsImage.jpeg_conversion)
79
+ @source.variant resize_and_flatten(VitalsImage.jpeg_conversion)
84
80
  end
85
81
  end
86
82
 
87
- def optimizations_with_optimal_quality(defaults = {})
88
- quality = @source.metadata[:optimal_quality] || defaults[:saver][:quality]
89
- defaults.merge quality: quality, "#{resize_mode}": dimensions
83
+ def resize_and_flatten(defaults = {})
84
+ resize = resize_mode != :resize_and_pad ? dimensions : dimensions.push(background: [255])
85
+ defaults.merge "#{resize_mode}": resize
90
86
  end
91
87
 
92
- def optimizations(defaults = {})
88
+ def resize(defaults = {})
93
89
  defaults.merge "#{resize_mode}": dimensions
94
90
  end
95
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitals_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.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-22 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0.3'
131
+ version: '0.5'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '0.3'
138
+ version: '0.5'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sqlite3
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -253,9 +253,10 @@ files:
253
253
  - lib/vitals_image/errors.rb
254
254
  - lib/vitals_image/gem_version.rb
255
255
  - lib/vitals_image/optimizer.rb
256
- - lib/vitals_image/optimizer/active_storage.rb
257
256
  - lib/vitals_image/optimizer/blank.rb
257
+ - lib/vitals_image/optimizer/invariable.rb
258
258
  - lib/vitals_image/optimizer/url.rb
259
+ - lib/vitals_image/optimizer/variable.rb
259
260
  - lib/vitals_image/test_case.rb
260
261
  - lib/vitals_image/version.rb
261
262
  homepage: https://github.com/FestaLab/vitals_image