@@ -98,16 +98,14 @@ def self.run_cmplx image, &block
98
98
end
99
99
100
100
new_format = image . format == :double ? :dpcomplex : :complex
101
- image = image . copy :format => new_format ,
102
- :bands => image . bands / 2
101
+ image = image . copy format : new_format , bands : image . bands / 2
103
102
end
104
103
105
104
image = block . ( image )
106
105
107
106
if not Image ::complex? original_format
108
107
new_format = image . format == :dpcomplex ? :double : :float
109
- image = image . copy :format => new_format ,
110
- :bands => image . bands * 2
108
+ image = image . copy format : new_format , bands : image . bands * 2
111
109
end
112
110
113
111
image
@@ -167,18 +165,26 @@ def inspect
167
165
"#{ interpretation } >"
168
166
end
169
167
170
- # Invoke a vips operation with {Vips::Operation::call}, using self as
168
+ # To support keyword args, we need to tell Ruby that final image
169
+ # arguments cannot be hashes of keywords.
170
+ #
171
+ # https://makandracards.com/makandra/36013-heads-up-ruby-implicitly-converts-a-hash-to-keyword-arguments
172
+ def to_hash
173
+ nil
174
+ end
175
+
176
+ # Invoke a vips operation with {Vips::Operation.call}, using self as
171
177
# the first input argument.
172
178
#
173
179
# @param name [String] vips operation to call
174
180
# @return result of vips operation
175
- def method_missing name , *args
176
- Vips ::Operation :: call name . to_s , [ self ] + args
181
+ def method_missing name , *args , ** options
182
+ Vips ::Operation . call name . to_s , [ self , * args ] , options
177
183
end
178
184
179
- # Invoke a vips operation with {Vips::Operation:: call}.
180
- def self . method_missing name , *args
181
- Vips ::Operation :: call name . to_s , args
185
+ # Invoke a vips operation with {Vips::Operation. call}.
186
+ def self . method_missing name , *args , ** options
187
+ Vips ::Operation . call name . to_s , args , options
182
188
end
183
189
184
190
# Return a new {Image} for a file on disc. This method can load
@@ -192,7 +198,7 @@ def self.method_missing name, *args
192
198
# You can also supply options as a hash, for example:
193
199
#
194
200
# ```
195
- # image = Vips::new_from_file "fred.jpg", : shrink => 2
201
+ # image = Vips::new_from_file "fred.jpg", shrink: 2
196
202
# ```
197
203
#
198
204
# The full set of options available depend upon the load operation that
@@ -227,7 +233,7 @@ def self.new_from_file name, opts = {}
227
233
loader = Vips ::vips_foreign_find_load filename
228
234
raise Vips ::Error if loader == nil
229
235
230
- Operation :: call loader , [ filename , opts ] , option_string
236
+ Operation . call loader , [ filename ] , opts , option_string
231
237
end
232
238
233
239
# Create a new {Image} for an image encoded, in a format such as
@@ -241,7 +247,7 @@ def self.new_from_file name, opts = {}
241
247
# or alternatively:
242
248
#
243
249
# ```
244
- # image = Vips::new_from_from_buffer memory_buffer, "", : shrink => 2
250
+ # image = Vips::new_from_from_buffer memory_buffer, "", shrink: 2
245
251
# ```
246
252
#
247
253
# The options available depend on the file format. Try something like:
@@ -265,7 +271,7 @@ def self.new_from_buffer data, option_string, opts = {}
265
271
loader = Vips ::vips_foreign_find_load_buffer data , data . length
266
272
raise Vips ::Error if loader == nil
267
273
268
- Vips ::Operation :: call loader , [ data , opts ] , option_string
274
+ Vips ::Operation . call loader , [ data ] , opts , option_string
269
275
end
270
276
271
277
def self . matrix_from_array width , height , array
@@ -349,10 +355,9 @@ def self.new_from_array array, scale = 1, offset = 0
349
355
# @return [Image] constant image
350
356
def new_from_image value
351
357
pixel = ( Vips ::Image . black ( 1 , 1 ) + value ) . cast ( format )
352
- image = pixel . embed 0 , 0 , width , height , :extend => :copy
353
- image . copy :interpretation => interpretation ,
354
- :xres => xres , :yres => yres ,
355
- :xoffset => xoffset , :yoffset => yoffset
358
+ image = pixel . embed 0 , 0 , width , height , extend : :copy
359
+ image . copy interpretation : interpretation ,
360
+ xres : xres , yres : yres , xoffset : xoffset , yoffset : yoffset
356
361
end
357
362
358
363
# Write this image to a file. Save options may be encoded in the
@@ -365,7 +370,7 @@ def new_from_image value
365
370
# or equivalently:
366
371
#
367
372
# ```
368
- # image.write_to_file "fred.jpg", :Q => 90
373
+ # image.write_to_file "fred.jpg", Q: 90
369
374
# ```
370
375
#
371
376
# The full set of save options depend on the selected saver. Try
@@ -392,7 +397,7 @@ def write_to_file name, opts = {}
392
397
raise Vips ::Error , "No known saver for '#{ filename } '."
393
398
end
394
399
395
- Vips ::Operation :: call saver , [ self , filename , opts ]
400
+ Vips ::Operation . call saver , [ self , filename ] , opts , option_string
396
401
397
402
write_gc
398
403
end
@@ -407,7 +412,7 @@ def write_to_file name, opts = {}
407
412
# or equivalently:
408
413
#
409
414
# ```
410
- # image.write_to_buffer ".jpg", :Q => 90
415
+ # image.write_to_buffer ".jpg", Q: 90
411
416
# ```
412
417
#
413
418
# The full set of save options depend on the selected saver. Try
@@ -430,7 +435,7 @@ def write_to_buffer format_string, opts = {}
430
435
raise Vips ::Error , "No known saver for '#{ filename } '."
431
436
end
432
437
433
- buffer = Vips ::Operation . call saver , [ self , opts ] , option_string
438
+ buffer = Vips ::Operation . call saver , [ self ] , opts , option_string
434
439
raise Vips ::Error if buffer == nil
435
440
436
441
write_gc
@@ -836,7 +841,7 @@ def [] index
836
841
if index . is_a? Range
837
842
n = index . end - index . begin
838
843
n += 1 if not index . exclude_end?
839
- extract_band index . begin , :n => n
844
+ extract_band index . begin , n : n
840
845
elsif index . is_a? Numeric
841
846
extract_band index
842
847
else
@@ -953,7 +958,7 @@ def bandjoin other
953
958
# @return [Real, Real, Real] maximum value, x coordinate of maximum, y
954
959
# coordinate of maximum
955
960
def maxpos
956
- v , opts = max :x => true , :y => true
961
+ v , opts = max x : true , y : true
957
962
x = opts [ 'x' ]
958
963
y = opts [ 'y' ]
959
964
return v , x , y
@@ -964,7 +969,7 @@ def maxpos
964
969
# @return [Real, Real, Real] minimum value, x coordinate of minimum, y
965
970
# coordinate of minimum
966
971
def minpos
967
- v , opts = min :x => true , :y => true
972
+ v , opts = min x : true , y : true
968
973
x = opts [ 'x' ]
969
974
y = opts [ 'y' ]
970
975
return v , x , y
@@ -1194,13 +1199,13 @@ def ifthenelse(th, el, opts = {})
1194
1199
match_image = [ th , el , self ] . find { |x | x . is_a? Vips ::Image }
1195
1200
1196
1201
if not th . is_a? Vips ::Image
1197
- th = Operation :: imageize match_image , th
1202
+ th = Operation . imageize match_image , th
1198
1203
end
1199
1204
if not el . is_a? Vips ::Image
1200
- el = Operation :: imageize match_image , el
1205
+ el = Operation . imageize match_image , el
1201
1206
end
1202
1207
1203
- Vips ::Operation . call "ifthenelse" , [ self , th , el , opts ]
1208
+ Vips ::Operation . call "ifthenelse" , [ self , th , el ] , opts
1204
1209
end
1205
1210
1206
1211
# Scale an image to uchar. This is the vips `scale` operation, but
0 commit comments