image_processing 1.11.0 → 1.12.2

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: 7e463ca2dcdc1e674b551a94acdfa2495677dd4fd17a79cbaf351727700cddf6
4
- data.tar.gz: 7970e3a7d1d8d70ab3291f7c3e892f1b2ebff9181bb74cc2ff4b1f36f9b39b80
3
+ metadata.gz: 31d06cb35ac94ec0787b21dd2118626f3a3a96685efab0d7eb58d9079b1fbf2c
4
+ data.tar.gz: 8f840074b8fe9511e59f4f005d144e39c9aba4d0699a48c29ffc6cb2513ec645
5
5
  SHA512:
6
- metadata.gz: a19939f654334cde66d3ae6c8bb451d1152a1f7e8385507b9649e88b151e99ed6c9005ed861e43c2d9c836327d93699685d74196b92c4b81e38c5d94abe545e5
7
- data.tar.gz: 292f1463f86eae88987dcc2dbe8d8e60ec458f9c33c41c1e1349a5dbadea12ba730ffde697158e239e64c28c14d0d14dc0c617ee439fe7380e73f0135dfecfd7
6
+ metadata.gz: 1d0fb1d9363b9b85e1895d05849a5c29b2c50b8213bf9e9d6ff8c2e1391a9bf6448a4e319a4cfd747183ec741ac42d6b1b1b9629ee91d97cc4a287ec6615042c
7
+ data.tar.gz: dd31dd0ca012ceb35aa276c5e00efd3e9bd2c40246f9b063ea39280ea13c546373fa641518fb55ebcf0e9d00ad6020be995b8d8636c8a3939bda31c643485cef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.12.2 (2022-03-01)
2
+
3
+ * Prevent remote shell execution when using `#apply` with operations coming from user input (@janko)
4
+
5
+ ## 1.12.1 (2020-11-06)
6
+
7
+ * Fix format fallback for files ending with a dot on Ruby 2.7+ (@coding-chimp)
8
+
9
+ ## 1.12.0 (2020-09-20)
10
+
11
+ * Add instrumentation support via `#instrumenter` (@janko)
12
+
1
13
  ## 1.11.0 (2020-05-17)
2
14
 
3
15
  * [minimagick] Handle destination format having no file extension (@janko)
data/README.md CHANGED
@@ -29,10 +29,18 @@ how to resize and process images.
29
29
 
30
30
  1. Install ImageMagick and/or libvips:
31
31
 
32
- ```sh
32
+ In a Mac terminal:
33
+
34
+ ```sh
33
35
  $ brew install imagemagick vips
34
36
  ```
35
37
 
38
+ In a debian/ubuntu terminal:
39
+
40
+ ```sh
41
+ $ sudo apt install imagemagick libvips
42
+ ```
43
+
36
44
  2. Add the gem to your Gemfile:
37
45
 
38
46
  ```rb
@@ -148,15 +156,50 @@ You can continue reading the API documentation for specific modules:
148
156
  See the **[wiki]** for additional "How To" guides for common scenarios. The wiki
149
157
  is publicly editable, so you're encouraged to add your own guides.
150
158
 
159
+ ## Instrumentation
160
+
161
+ You can register an `#instrumenter` block for a given pipeline, which will wrap
162
+ the pipeline execution, allowing you to record performance metrics.
163
+
164
+ ```rb
165
+ pipeline = ImageProcessing::Vips.instrumenter do |**options, &processing|
166
+ options[:source] #=> #<File:...>
167
+ options[:loader] #=> { fail: true }
168
+ options[:saver] #=> { quality: 85 }
169
+ options[:format] #=> "png"
170
+ options[:operations] #=> [[:resize_to_limit, 500, 500], [:flip, [:horizontal]]]
171
+ options[:processor] #=> ImageProcessing::Vips::Processor
172
+
173
+ ActiveSupport::Notifications.instrument("process.image_processing", **options) do
174
+ processing.call # calls the pipeline
175
+ end
176
+ end
177
+
178
+ pipeline
179
+ .source(image)
180
+ .loader(fail: true)
181
+ .saver(quality: 85)
182
+ .convert("png")
183
+ .resize_to_limit(500, 500)
184
+ .flip(:horizontal)
185
+ .call # calls instrumenter
186
+ ```
151
187
 
152
188
  ## Contributing
153
189
 
154
190
  Our test suite requires both `imagemagick` and `libvips` libraries to be installed.
155
191
 
192
+ In a Mac terminal:
193
+
156
194
  ```
157
195
  $ brew install imagemagick vips
158
196
  ```
159
197
 
198
+ In a debian/ubuntu terminal:
199
+ ```shell
200
+ sudo apt install imagemagick libvips
201
+ ```
202
+
160
203
  Afterwards you can run tests with
161
204
 
162
205
  ```
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "minitest", "~> 5.8"
24
24
  spec.add_development_dependency "minitest-hooks", ">= 1.4.2"
25
25
  spec.add_development_dependency "minispec-metadata"
26
- spec.add_development_dependency "phashion" unless RUBY_ENGINE == "jruby"
26
+ spec.add_development_dependency "dhash-vips"
27
27
  end
@@ -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!(**options)
13
- Pipeline.new(self.options).call(**options)
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)
@@ -29,27 +34,17 @@ module ImageProcessing
29
34
  def apply(operations)
30
35
  operations.inject(self) do |builder, (name, argument)|
31
36
  if argument == true || argument == nil
32
- builder.send(name)
37
+ builder.public_send(name)
33
38
  elsif argument.is_a?(Array)
34
- builder.send(name, *argument)
39
+ builder.public_send(name, *argument)
35
40
  elsif argument.is_a?(Hash)
36
- builder.send(name, **argument)
41
+ builder.public_send(name, **argument)
37
42
  else
38
- builder.send(name, argument)
43
+ builder.public_send(name, argument)
39
44
  end
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]]
@@ -59,26 +54,42 @@ module ImageProcessing
59
54
  # the source file and destination.
60
55
  def call(file = nil, destination: nil, **call_options)
61
56
  options = {}
62
- options = options.merge(source: file) if file
63
- options = options.merge(destination: destination) if destination
57
+ options[:source] = file if file
58
+ options[:destination] = destination if destination
64
59
 
65
60
  branch(**options).call!(**call_options)
66
61
  end
67
62
 
68
63
  # Creates a new builder object, merging current options with new options.
69
- def branch(loader: nil, saver: nil, operations: nil, **other_options)
70
- options = respond_to?(:options) ? self.options : DEFAULT_OPTIONS
64
+ def branch(**new_options)
65
+ if self.is_a?(Builder)
66
+ options = self.options
67
+ else
68
+ options = DEFAULT_OPTIONS.merge(processor: self::Processor)
69
+ end
71
70
 
72
- options = options.merge(loader: options[:loader].merge(loader)) if loader
73
- options = options.merge(saver: options[:saver].merge(saver)) if saver
74
- options = options.merge(operations: options[:operations] + operations) if operations
75
- options = options.merge(processor: self::Processor) unless self.is_a?(Builder)
76
- options = options.merge(other_options)
71
+ options = options.merge(new_options) do |key, old_value, new_value|
72
+ case key
73
+ when :loader, :saver then old_value.merge(new_value)
74
+ when :operations then old_value + new_value
75
+ else new_value
76
+ end
77
+ end
78
+
79
+ Builder.new(options.freeze)
80
+ end
81
+
82
+ private
77
83
 
78
- options.freeze
84
+ # Assume that any unknown method names an operation supported by the
85
+ # processor. Add a bang ("!") if you want processing to be performed.
86
+ def method_missing(name, *args, &block)
87
+ return super if name.to_s.end_with?("?")
88
+ return send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
79
89
 
80
- Builder.new(options)
90
+ operation(name, *args, &block)
81
91
  end
92
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
82
93
 
83
94
  # Empty options which the builder starts with.
84
95
  DEFAULT_OPTIONS = {
@@ -37,9 +37,9 @@ module ImageProcessing
37
37
 
38
38
  # Determines the appropriate destination image format.
39
39
  def destination_format
40
- format = File.extname(destination)[1..-1] if destination
40
+ format = determine_format(destination) if destination
41
41
  format ||= self.format
42
- format ||= File.extname(source_path)[1..-1] if source_path
42
+ format ||= determine_format(source_path) if source_path
43
43
 
44
44
  format || DEFAULT_FORMAT
45
45
  end
@@ -93,5 +93,11 @@ module ImageProcessing
93
93
  @source
94
94
  end
95
95
  end
96
+
97
+ def determine_format(file_path)
98
+ extension = File.extname(file_path)
99
+
100
+ extension[1..-1] if extension.size > 1
101
+ end
96
102
  end
97
103
  end
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.11.0"
2
+ VERSION = "1.12.2"
3
3
  end
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.11.0
4
+ version: 1.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-17 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -107,7 +107,7 @@ dependencies:
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  - !ruby/object:Gem::Dependency
110
- name: phashion
110
+ name: dhash-vips
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
@@ -144,7 +144,7 @@ homepage: https://github.com/janko/image_processing
144
144
  licenses:
145
145
  - MIT
146
146
  metadata: {}
147
- post_install_message:
147
+ post_install_message:
148
148
  rdoc_options: []
149
149
  require_paths:
150
150
  - lib
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.1.1
163
- signing_key:
162
+ rubygems_version: 3.3.3
163
+ signing_key:
164
164
  specification_version: 4
165
165
  summary: High-level wrapper for processing images for the web with ImageMagick or
166
166
  libvips.