image_processing 1.8.0 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f22578c76658031df98eee4b527240f093f67685fe500203133cc0926c98651a
4
- data.tar.gz: 00a25b55f2ac02e1ba2f9fa680df72bd686a6e364474b734673f30c28673df02
3
+ metadata.gz: ffa40592c60c9cdd802c66603dd364a5eabc2c3b0b784df8e6646bab22976916
4
+ data.tar.gz: fdb4f77ccd655719bdd9650816ae20fd80db7f192d267db8b3081a9e4beae476
5
5
  SHA512:
6
- metadata.gz: dd79bd00804d9c2dde5e51d0fffe6e48cdd3ee5d69333cbe4a5471ce3714c0be43b4cf39df7d464fe7b23d76c172c417612de37a50d3173f2bffc130eac5498e
7
- data.tar.gz: 0f13da9ed2363bc7f763f5ad73be4e6981344879472747905e57aa48eb0bce9fc261b39f6168ed8ce679fc5da70270321302858ba50df1a7362a899f6fceee59
6
+ metadata.gz: b1be056214e0da7b38cc229bcd4e48d7962514777881de9c93ddd68ccb5de8bd29bfada6afbf03a78007aee860d1bb706dc2f35f3e192c0861110df8e71c3a31
7
+ data.tar.gz: fa16784ff04521cb24608869f159185586e61f9ecaedc977ac89e550a1209e921f91590ea71b27fbeb4ab3a49f1ee545fd44d8291d83687d4e309d31dada3a28
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.9.0 (2019-04-09)
2
+
3
+ * Drop support for MRI 2.2 and 2.3 (@janko)
4
+
5
+ * [vips] Allow forcing a specific loader or saver (@janko)
6
+
1
7
  ## 1.8.0 (2019-02-25)
2
8
 
3
9
  * [vips] Perform resize-on-load when possible, significantly improving resizing speed (@janko)
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "image_processing"
5
5
  spec.version = ImageProcessing::VERSION
6
6
 
7
- spec.required_ruby_version = ">= 2.0"
7
+ spec.required_ruby_version = ">= 2.4"
8
8
 
9
9
  spec.summary = "Set of higher-level helper methods for image processing."
10
10
  spec.description = "Set of higher-level helper methods for image processing."
@@ -25,7 +25,7 @@ module ImageProcessing
25
25
  # Initializes the image on disk into a MiniMagick::Tool object. Accepts
26
26
  # additional options related to loading the image (e.g. geometry).
27
27
  # Additionally auto-orients the image to be upright.
28
- def self.load_image(path_or_magick, operations: [], page: nil, geometry: nil, auto_orient: true, **options)
28
+ def self.load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **options)
29
29
  if path_or_magick.is_a?(::MiniMagick::Tool)
30
30
  magick = path_or_magick
31
31
  else
@@ -195,7 +195,7 @@ module ImageProcessing
195
195
 
196
196
  if layers.any?
197
197
  layers.each { |path| File.delete(path) }
198
- raise Error, "Multi-layer image is being converted into a single-layer format. You should either process individual layers or set :allow_splitting to true. See https://github.com/janko/image_processing/wiki/Splitting-a-PDF-into-multiple-images for how to process each layer individually."
198
+ raise Error, "Source format is multi-layer, but destination format is single-layer. If you care only about the first layer, add `.loader(page: 0)` to your pipeline. If you want to process each layer, see https://github.com/janko/image_processing/wiki/Splitting-a-PDF-into-multiple-images or use `.saver(allow_splitting: true)`."
199
199
  end
200
200
  end
201
201
 
@@ -6,7 +6,14 @@ module ImageProcessing
6
6
  fail Error, "invalid source: #{source.inspect}"
7
7
  end
8
8
 
9
- accumulator = load_image(source, operations: operations, **loader)
9
+ if operations.dig(0, 0).to_s.start_with?("resize_") &&
10
+ loader.empty? &&
11
+ supports_resize_on_load?
12
+
13
+ accumulator = source
14
+ else
15
+ accumulator = load_image(source, **loader)
16
+ end
10
17
 
11
18
  operations.each do |operation|
12
19
  accumulator = apply_operation(accumulator, operation)
@@ -40,6 +47,10 @@ module ImageProcessing
40
47
  end
41
48
  end
42
49
 
50
+ def self.supports_resize_on_load?
51
+ false
52
+ end
53
+
43
54
  def initialize(accumulator = nil)
44
55
  @accumulator = accumulator
45
56
  end
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.8.0"
2
+ VERSION = "1.9.0"
3
3
  end
@@ -27,34 +27,41 @@ module ImageProcessing
27
27
  # Loads the image on disk into a Vips::Image object. Accepts additional
28
28
  # loader-specific options (e.g. interlacing). Afterwards auto-rotates the
29
29
  # image to be upright.
30
- def self.load_image(path_or_image, operations: [], autorot: true, **options)
30
+ def self.load_image(path_or_image, loader: nil, autorot: true, **options)
31
31
  if path_or_image.is_a?(::Vips::Image)
32
32
  image = path_or_image
33
33
  else
34
34
  path = path_or_image
35
35
 
36
- # utilize resize-on-load optimization when possible
37
- return path if operations.any? &&
38
- operations[0][0].to_s.start_with?("resize_") &&
39
- options.empty?
40
-
41
- options = Utils.select_valid_loader_options(path, options)
42
-
43
- image = ::Vips::Image.new_from_file(path, **options)
36
+ if loader
37
+ image = ::Vips::Image.public_send(:"#{loader}load", path, **options)
38
+ else
39
+ options = Utils.select_valid_loader_options(path, options)
40
+ image = ::Vips::Image.new_from_file(path, **options)
41
+ end
44
42
  end
45
43
 
46
44
  image = image.autorot if autorot && !options.key?(:autorotate)
47
45
  image
48
46
  end
49
47
 
48
+ # See #thumbnail.
49
+ def self.supports_resize_on_load?
50
+ true
51
+ end
52
+
50
53
  # Writes the Vips::Image object to disk. This starts the processing
51
54
  # pipeline defined in the Vips::Image object. Accepts additional
52
55
  # saver-specific options (e.g. quality).
53
- def self.save_image(image, destination_path, quality: nil, **options)
56
+ def self.save_image(image, path, saver: nil, quality: nil, **options)
54
57
  options = options.merge(Q: quality) if quality
55
- options = Utils.select_valid_saver_options(destination_path, options)
56
58
 
57
- image.write_to_file(destination_path, **options)
59
+ if saver
60
+ image.public_send(:"#{saver}save", path, **options)
61
+ else
62
+ options = Utils.select_valid_saver_options(path, options)
63
+ image.write_to_file(path, **options)
64
+ end
58
65
  end
59
66
 
60
67
  # Resizes the image to not be larger than the specified dimensions.
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.8.0
4
+ version: 1.9.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: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -151,14 +151,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ">="
153
153
  - !ruby/object:Gem::Version
154
- version: '2.0'
154
+ version: '2.4'
155
155
  required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.0.1
161
+ rubygems_version: 3.0.3
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Set of higher-level helper methods for image processing.