image_processing 1.11.0 → 1.12.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.
Potentially problematic release.
This version of image_processing might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +28 -0
- data/lib/image_processing/builder.rb +18 -2
- data/lib/image_processing/chainable.rb +31 -22
- data/lib/image_processing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e86e76046f3b8e0b9fd36a71d52b158a923c75f33848692de1e199ecb17366f
|
4
|
+
data.tar.gz: 7267f19b5cb3224a61e04be0a0d3b3f17d353750a1a522a11f2912b9ba49b809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 473958a39a8e760cdb9d352399190f1cdea0dcd915ad729ec740fb7f424dc05041c43fe1085439c0f54763c388b83c2b7dcf32f66cc15caa9dbc0f21c325a166
|
7
|
+
data.tar.gz: ac3cc41432e9dc786035f77c721eb1407c84c6307fccc9d8f01f42ca909618229134411f503eeeb770809f620804468750414e6dc8900c442a46d08d3d02e660
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -148,6 +148,34 @@ You can continue reading the API documentation for specific modules:
|
|
148
148
|
See the **[wiki]** for additional "How To" guides for common scenarios. The wiki
|
149
149
|
is publicly editable, so you're encouraged to add your own guides.
|
150
150
|
|
151
|
+
## Instrumentation
|
152
|
+
|
153
|
+
You can register an `#instrumenter` block for a given pipeline, which will wrap
|
154
|
+
the pipeline execution, allowing you to record performance metrics.
|
155
|
+
|
156
|
+
```rb
|
157
|
+
pipeline = ImageProcessing::Vips.instrumenter do |**options, &processing|
|
158
|
+
options[:source] #=> #<File:...>
|
159
|
+
options[:loader] #=> { fail: true }
|
160
|
+
options[:saver] #=> { quality: 85 }
|
161
|
+
options[:format] #=> "png"
|
162
|
+
options[:operations] #=> [[:resize_to_limit, 500, 500], [:flip, [:horizontal]]]
|
163
|
+
options[:processor] #=> ImageProcessing::Vips::Processor
|
164
|
+
|
165
|
+
ActiveSupport::Notifications.instrument("process.image_processing", **options) do
|
166
|
+
processing.call # calls the pipeline
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
pipeline
|
171
|
+
.source(image)
|
172
|
+
.loader(fail: true)
|
173
|
+
.saver(quality: 85)
|
174
|
+
.convert("png")
|
175
|
+
.resize_to_limit(500, 500)
|
176
|
+
.flip(:horizontal)
|
177
|
+
.call # calls instrumenter
|
178
|
+
```
|
151
179
|
|
152
180
|
## Contributing
|
153
181
|
|
@@ -9,8 +9,24 @@ module ImageProcessing
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Calls the pipeline to perform the processing from built options.
|
12
|
-
def call!(**
|
13
|
-
|
12
|
+
def call!(**call_options)
|
13
|
+
instrument do
|
14
|
+
Pipeline.new(pipeline_options).call(**call_options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def instrument
|
21
|
+
return yield unless options[:instrumenter]
|
22
|
+
|
23
|
+
result = nil
|
24
|
+
options[:instrumenter].call(**pipeline_options) { result = yield }
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
def pipeline_options
|
29
|
+
options.reject { |key, _| key == :instrumenter }
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
@@ -21,6 +21,11 @@ module ImageProcessing
|
|
21
21
|
branch saver: options
|
22
22
|
end
|
23
23
|
|
24
|
+
# Register instrumentation block that will be called around the pipeline.
|
25
|
+
def instrumenter(&block)
|
26
|
+
branch instrumenter: block
|
27
|
+
end
|
28
|
+
|
24
29
|
# Add multiple operations as a hash or an array.
|
25
30
|
#
|
26
31
|
# .apply(resize_to_limit: [400, 400], strip: true)
|
@@ -40,16 +45,6 @@ module ImageProcessing
|
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
|
-
# Assume that any unknown method names an operation supported by the
|
44
|
-
# processor. Add a bang ("!") if you want processing to be performed.
|
45
|
-
def method_missing(name, *args, &block)
|
46
|
-
return super if name.to_s.end_with?("?")
|
47
|
-
return send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
|
48
|
-
|
49
|
-
operation(name, *args, &block)
|
50
|
-
end
|
51
|
-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
52
|
-
|
53
48
|
# Add an operation defined by the processor.
|
54
49
|
def operation(name, *args, &block)
|
55
50
|
branch operations: [[name, args, *block]]
|
@@ -58,27 +53,41 @@ module ImageProcessing
|
|
58
53
|
# Call the defined processing and get the result. Allows specifying
|
59
54
|
# the source file and destination.
|
60
55
|
def call(file = nil, destination: nil, **call_options)
|
61
|
-
options = {}
|
62
|
-
options = options.merge(source: file) if file
|
63
|
-
options = options.merge(destination: destination) if destination
|
56
|
+
options = { source: file, destination: destination }.compact
|
64
57
|
|
65
58
|
branch(**options).call!(**call_options)
|
66
59
|
end
|
67
60
|
|
68
61
|
# Creates a new builder object, merging current options with new options.
|
69
|
-
def branch(
|
70
|
-
|
62
|
+
def branch(**new_options)
|
63
|
+
if self.is_a?(Builder)
|
64
|
+
options = self.options
|
65
|
+
else
|
66
|
+
options = DEFAULT_OPTIONS.merge(processor: self::Processor)
|
67
|
+
end
|
71
68
|
|
72
|
-
options = options.merge(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
69
|
+
options = options.merge(new_options) do |key, old_value, new_value|
|
70
|
+
case key
|
71
|
+
when :loader, :saver then old_value.merge(new_value)
|
72
|
+
when :operations then old_value + new_value
|
73
|
+
else new_value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
Builder.new(options.freeze)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
77
81
|
|
78
|
-
|
82
|
+
# Assume that any unknown method names an operation supported by the
|
83
|
+
# processor. Add a bang ("!") if you want processing to be performed.
|
84
|
+
def method_missing(name, *args, &block)
|
85
|
+
return super if name.to_s.end_with?("?")
|
86
|
+
return send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
|
79
87
|
|
80
|
-
|
88
|
+
operation(name, *args, &block)
|
81
89
|
end
|
90
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
82
91
|
|
83
92
|
# Empty options which the builder starts with.
|
84
93
|
DEFAULT_OPTIONS = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_magick
|