image_processing 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.

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: 5b28b25634ec49e61835850b56f7c1c46b4d0e10ea99fbb6ef05c238e307d348
4
- data.tar.gz: 348ff75f2a0779c085341248ac9cf4e9a931e984a3ba2e2e016c77dd63cc04e0
3
+ metadata.gz: c73cfe4047169c0385afc59779c47cc43385b8c02a82e540d8ad53adbd32aa41
4
+ data.tar.gz: 6ae50e569a9bad8b408c7f17a2eaded27e939be43c8b72f956d19875e2de5116
5
5
  SHA512:
6
- metadata.gz: 85f39d0e536bddda22b5a79d5a0cc95496cf8eccccb536549ac209dbad3850b83add4797420a165582c666230015a1a4f969c0846e026f950a0d4dee1c5d00a8
7
- data.tar.gz: e9b452b98df5b6f96cccf89b51a17b6ea3d06197adce46549d441fbd6822bcecac58cb9bf8e8ddc8ad14c3b144f8a8d703cb4d183d615ad349337430f6da9b7c
6
+ metadata.gz: deae9e4f3c13765f296aaf3801d02f55756518e077c38e1e6df89fc6c478fda48de41866292326684be06aeac3dedcd4fd1bd4688b09cc2b0ba858d6034e6416
7
+ data.tar.gz: 152da0d976a408e8c2dbf66e5054df86e22ae8006381833e4d0c845f7c643acb55355efeb30f910ca32c0b19fb3171503f92fcef240d26728151a0a8de68ec54
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## HEAD
2
+
3
+ * [vips] In `#composite` accept `:offset` option for the position of the overlay image (@janko-m)
4
+
5
+ * [vips] In `#composite` accept `:gravity` option for the direction of the overlay image (@janko-m)
6
+
7
+ * [vips] In `#composite` accept blend mode as an optional `:mode` parameter which defaults to `:over` (@janko-m)
8
+
9
+ * [minimagick] In `#composite` rename `:compose` option to `:mode` (@janko-m)
10
+
11
+ * [minimagick] In `#composite` replace `:geometry` option with `:offset` which accepts an array (@janko-m)
12
+
1
13
  ## 1.5.0 (2018-07-10)
2
14
 
3
15
  * [minimagick, vips] Add `#composite` method (@janko-m)
@@ -76,16 +76,27 @@ module ImageProcessing
76
76
  magick.rotate(degrees)
77
77
  end
78
78
 
79
- def composite(overlay = :none, mask: nil, compose: nil, gravity: nil, geometry: nil, args: nil, &block)
79
+ def composite(overlay = :none, mask: nil, mode: nil, gravity: nil, offset: nil, args: nil, **options, &block)
80
80
  return magick.composite if overlay == :none
81
81
 
82
+ if options.key?(:compose)
83
+ warn "[IMAGE_PROCESSING] The :compose parameter in #composite has been renamed to :mode, the :compose alias will be removed in ImageProcessing 2."
84
+ mode = options[:compose]
85
+ end
86
+
87
+ if options.key?(:geometry)
88
+ warn "[IMAGE_PROCESSING] The :geometry parameter in #composite has been deprecated and will be removed in ImageProcessing 2. Use :offset instead, e.g. `geometry: \"+10+15\"` should be replaced with `offset: [10, 15]`."
89
+ geometry = options[:geometry]
90
+ end
91
+ geometry = "%+d%+d" % offset if offset
92
+
82
93
  overlay_path = convert_to_path(overlay, "overlay")
83
94
  mask_path = convert_to_path(mask, "mask") if mask
84
95
 
85
96
  magick << overlay_path
86
97
  magick << mask_path if mask_path
87
98
 
88
- magick.compose(compose) if compose
99
+ magick.compose(mode) if mode
89
100
  define(compose: { args: args }) if args
90
101
 
91
102
  magick.gravity(gravity) if gravity
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -78,22 +78,25 @@ module ImageProcessing
78
78
  end
79
79
  end
80
80
 
81
- def composite(other, mode, **options)
82
- other = [other] unless other.is_a?(Array)
83
-
84
- other = other.map do |object|
85
- if object.is_a?(String)
86
- ::Vips::Image.new_from_file(object)
87
- elsif object.respond_to?(:to_path)
88
- ::Vips::Image.new_from_file(object.to_path)
89
- elsif object.respond_to?(:path)
90
- ::Vips::Image.new_from_file(object.path)
91
- else
92
- object
93
- end
81
+ def composite(overlay, _mode = nil, mode: :over, gravity: :"north-west", offset: nil, **options)
82
+ if _mode
83
+ overlay = [overlay] unless overlay.is_a?(Array)
84
+ overlay = overlay.map { |object| convert_to_image(object, "overlay") }
85
+
86
+ return image.composite(overlay, _mode, **options)
87
+ end
88
+
89
+ overlay = convert_to_image(overlay, "overlay")
90
+ overlay = overlay.add_alpha unless overlay.has_alpha? # so that #gravity can use transparent background
91
+
92
+ if offset
93
+ opposite_gravity = gravity.to_s.gsub(/\w+/, "north"=>"south", "south"=>"north", "east"=>"west", "west"=>"east")
94
+ overlay = overlay.gravity(opposite_gravity, overlay.width + offset.first, overlay.height + offset.last)
94
95
  end
95
96
 
96
- image.composite(other, mode, **options)
97
+ overlay = overlay.gravity(gravity, image.width, image.height)
98
+
99
+ image.composite(overlay, mode, **options)
97
100
  end
98
101
 
99
102
  # make Vips::Image#set, #set_type, and #set_value chainable
@@ -116,6 +119,22 @@ module ImageProcessing
116
119
  [width || ::Vips::MAX_COORD, height || ::Vips::MAX_COORD]
117
120
  end
118
121
 
122
+ def convert_to_image(object, name)
123
+ return object if object.is_a?(::Vips::Image)
124
+
125
+ if object.is_a?(String)
126
+ path = object
127
+ elsif object.respond_to?(:to_path)
128
+ path = object.to_path
129
+ elsif object.respond_to?(:path)
130
+ path = object.path
131
+ else
132
+ raise ArgumentError, "#{name} must be a Vips::Image, String, Pathname, or respond to #path"
133
+ end
134
+
135
+ ::Vips::Image.new_from_file(path)
136
+ end
137
+
119
138
  module Utils
120
139
  module_function
121
140
 
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.5.0
4
+ version: 1.6.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: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick