-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathimage_spec.rb
750 lines (601 loc) · 19.6 KB
/
image_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
require "spec_helper"
RSpec.describe Vips::Image do
it "can save an image to a file" do
filename = timg "x.v"
image = Vips::Image.black(16, 16) + 128
image.write_to_file filename
expect(File.exist?(filename)).to be true
end
it "can load an image from a file" do
filename = timg "x.v"
image = Vips::Image.black(16, 16) + 128
image.write_to_file(filename)
x = Vips::Image.new_from_file filename
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "can load an image from memory" do
image = Vips::Image.black(16, 16) + 128
data = image.write_to_memory
x = Vips::Image.new_from_memory data,
image.width, image.height, image.bands, image.format
# GC to try to trigger a segv if data hasn't been reffed by
# new_from_memory
GC.start
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "can load an image from memory by memory pointer" do
data = FFI::MemoryPointer.new(:uchar, 16 * 16)
data.put_array_of_uchar(0, Array.new(16 * 16, 128))
x = Vips::Image.new_from_memory data, 16, 16, 1, :uchar
# GC to try to trigger a segv if data hasn't been reffed by
# new_from_memory
GC.start
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "can load an image from memory by size aware address pointer" do
memory = FFI::MemoryPointer.new(:uchar, 16 * 16)
memory.put_array_of_uchar(0, Array.new(16 * 16, 128))
data = FFI::Pointer.new(memory)
# JRuby's FFI implementation loses the size information
data = data.slice(0, 16 * 16) if defined?(JRUBY_VERSION)
x = Vips::Image.new_from_memory data, 16, 16, 1, :uchar
# GC to try to trigger a segv if data hasn't been reffed by
# new_from_memory
GC.start
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "throws an error when trying to load an image from memory with unknown size" do
data = FFI::Pointer.new(1)
expect { Vips::Image.new_from_memory(data, 16, 16, 1, :uchar) }.to raise_error(Vips::Error)
end
it "can load an image from memory and copy" do
image = Vips::Image.black(16, 16) + 128
data = image.write_to_memory
x = Vips::Image.new_from_memory_copy data,
image.width, image.height, image.bands, image.format
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "can load and copy an image from memory by memory pointer" do
data = FFI::MemoryPointer.new(:uchar, 16 * 16)
data.put_array_of_uchar(0, Array.new(16 * 16, 128))
x = Vips::Image.new_from_memory_copy data, 16, 16, 1, :uchar
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "can load and copy an image from memory by size aware address pointer" do
memory = FFI::MemoryPointer.new(:uchar, 16 * 16)
memory.put_array_of_uchar(0, Array.new(16 * 16, 128))
data = FFI::Pointer.new(memory)
# JRuby's FFI implementation loses the size information
data = data.slice(0, 16 * 16) if defined?(JRUBY_VERSION)
x = Vips::Image.new_from_memory_copy data, 16, 16, 1, :uchar
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "throws an error when trying to load and copy from memory with unknown size" do
data = FFI::Pointer.new(1)
expect { Vips::Image.new_from_memory_copy(data, 16, 16, 1, :uchar) }.to raise_error(Vips::Error)
end
it "can load an image from a read pointer" do
image = Vips::Image.black(16, 16) + 128
data = image.read_ptr
expect(data).to be_a(FFI::Pointer)
expect(data.size).to eq(1024)
x = Vips::Image.new_from_memory data,
image.width, image.height, image.bands, image.format
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
if has_jpeg?
it "can save an image to a buffer" do
image = Vips::Image.black(16, 16) + 128
buffer = image.write_to_buffer ".jpg"
expect(buffer.length).to be > 100
end
end
if has_jpeg?
it "can load an image from a buffer" do
image = Vips::Image.black(16, 16) + 128
buffer = image.write_to_buffer ".jpg"
x = Vips::Image.new_from_buffer buffer, ""
expect(x.width).to eq(16)
expect(x.height).to eq(16)
end
end
it "can make an image from a 2d array" do
image = Vips::Image.new_from_array [[1, 2], [3, 4]]
expect(image.width).to eq(2)
expect(image.height).to eq(2)
expect(image.bands).to eq(1)
expect(image.avg).to eq(2.5)
end
it "can make an image from a 1d array" do
image = Vips::Image.new_from_array [1, 2]
expect(image.width).to eq(2)
expect(image.height).to eq(1)
expect(image.bands).to eq(1)
expect(image.avg).to eq(1.5)
end
it "can use array consts for image args" do
r = Vips::Image.black(16, 16)
r = r.draw_rect 255, 10, 12, 1, 1
g = Vips::Image.black(16, 16)
g = g.draw_rect 255, 10, 11, 1, 1
b = Vips::Image.black(16, 16)
b = b.draw_rect 255, 10, 10, 1, 1
im = r.bandjoin([g, b])
expect(im.width).to eq(16)
expect(im.height).to eq(16)
expect(im.bands).to eq(3)
im = im.conv [
[0.11, 0.11, 0.11],
[0.11, 0.11, 0.11],
[0.11, 0.11, 0.11]
], precision: :float
expect(im.width).to eq(16)
expect(im.height).to eq(16)
expect(im.bands).to eq(3)
end
it "can set scale and offset on a convolution mask" do
image = Vips::Image.new_from_array [1, 2], 8, 2
expect(image.width).to eq(2)
expect(image.height).to eq(1)
expect(image.bands).to eq(1)
expect(image.scale).to eq(8)
expect(image.offset).to eq(2)
expect(image.avg).to eq(1.5)
end
it "supports imagescale" do
image = Vips::Image.new_from_array [1, 2], 8, 2
image = image.scaleimage
expect(image.width).to eq(2)
expect(image.height).to eq(1)
expect(image.max).to eq(255)
expect(image.min).to eq(0)
end
if has_jpeg?
it "can load a sample jpg image file" do
x = Vips::Image.new_from_file simg("wagon.jpg")
expect(x.width).to eq(685)
expect(x.height).to eq(478)
expect(x.bands).to eq(3)
expect(x.avg).to be_within(0.001).of(109.789)
end
end
if has_jpeg?
it "can load a sample jpg image buffer" do
str = File.binread(simg("wagon.jpg"))
x = Vips::Image.new_from_buffer str, ""
expect(x.width).to eq(685)
expect(x.height).to eq(478)
expect(x.bands).to eq(3)
expect(x.avg).to be_within(0.001).of(109.789)
end
end
if has_jpeg?
it "can load a sample jpg image utf-8 buffer" do
str = File.read(simg("wagon.jpg"))
x = Vips::Image.new_from_buffer str, ""
expect(x.width).to eq(685)
expect(x.height).to eq(478)
expect(x.bands).to eq(3)
expect(x.avg).to be_within(0.001).of(109.789)
end
end
if has_jpeg?
it "can extract an ICC profile from a jpg image" do
x = Vips::Image.new_from_file simg("icc.jpg")
expect(x.width).to eq(2800)
expect(x.height).to eq(2100)
expect(x.bands).to eq(3)
expect(x.avg).to be_within(0.001).of(109.189)
profile = x.get_value "icc-profile-data"
expect(profile.class).to eq(String)
expect(profile.length).to eq(2360)
end
end
if has_jpeg?
it "can set an ICC profile on a jpg image" do
x = Vips::Image.new_from_file simg("icc.jpg")
profile = File.binread(simg("lcd.icc"))
x = x.copy
x.set_value "icc-profile-data", profile
x.write_to_file(timg("x.jpg"))
x = Vips::Image.new_from_file timg("x.jpg")
expect(x.width).to eq(2800)
expect(x.height).to eq(2100)
expect(x.bands).to eq(3)
expect(x.avg).to be_within(0.1).of(109.189)
profile = x.get_value "icc-profile-data"
expect(profile.class).to eq(String)
expect(profile.length).to eq(3048)
end
end
if has_jpeg?
it "can load a sample jpg image" do
x = Vips::Image.new_from_file simg("wagon.jpg")
expect(x.width).to eq(685)
expect(x.height).to eq(478)
expect(x.bands).to eq(3)
expect(x.avg).to be_within(0.001).of(109.789)
end
end
it "has binary arithmetic operator overloads with constants" do
image = Vips::Image.black(16, 16) + 128
image += 128
image -= 128
image *= 2
image /= 2
image %= 100
image += 100
image **= 2
image **= 0.5
image <<= 1
image >>= 1
image |= 64
image &= 32
image ^= 128
expect(image.avg).to eq(128)
end
it "has binary arithmetic operator overloads with array constants" do
image = Vips::Image.black(16, 16, bands: 3) + 128
image += [128, 0, 0]
image -= [128, 0, 0]
image *= [2, 1, 1]
image /= [2, 1, 1]
image %= [100, 99, 98]
image += [100, 99, 98]
image **= [2, 3, 4]
image **= [1.0 / 2.0, 1.0 / 3.0, 1.0 / 4.0]
image <<= [1, 2, 3]
image >>= [1, 2, 3]
image |= [64, 128, 256]
image &= [64, 128, 256]
image ^= [64 + 128, 0, 256 + 128]
expect(image.avg).to eq(128)
end
it "has binary arithmetic operator overloads with image args" do
image = Vips::Image.black(16, 16) + 128
x = image
x += image
x -= image
x *= image
x /= image
x %= image
x += image
x |= image
x &= image
x ^= image
expect(x.avg).to eq(0)
end
it "has relational operator overloads with constants" do
image = Vips::Image.black(16, 16) + 128
expect((image > 128).avg).to eq(0)
expect((image >= 128).avg).to eq(255)
expect((image < 128).avg).to eq(0)
expect((image <= 128).avg).to eq(255)
expect((image == 128).avg).to eq(255)
expect((image != 128).avg).to eq(0)
end
it "has relational operator overloads with array constants" do
image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130]
expect((image > [100, 128, 130]).avg).to eq(0)
expect((image >= [100, 128, 130]).avg).to eq(255)
expect((image < [100, 128, 130]).avg).to eq(0)
expect((image <= [100, 128, 130]).avg).to eq(255)
expect((image == [100, 128, 130]).avg).to eq(255)
expect((image != [100, 128, 130]).avg).to eq(0)
end
it "has relational operator overloads with image args" do
image = Vips::Image.black(16, 16) + 128
expect((image > image).avg).to eq(0)
expect((image >= image).avg).to eq(255)
expect((image < image).avg).to eq(0)
expect((image <= image).avg).to eq(255)
expect((image == image).avg).to eq(255)
expect((image != image).avg).to eq(0)
end
it "has band extract with numeric arg" do
image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130]
x = image[1]
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(1)
expect(x.avg).to eq(128)
end
it "has band extract with range arg" do
image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130]
x = image[1..2]
expect(x.width).to eq(16)
expect(x.height).to eq(16)
expect(x.bands).to eq(2)
expect(x.avg).to eq(129)
end
it "has rounding members" do
# need to avoid rounding down to 0.499999
image = Vips::Image.black(16, 16) + 0.500001
expect(image.floor.avg).to eq(0)
expect(image.ceil.avg).to eq(1)
expect(image.rint.avg).to eq(1)
end
it "has bandsplit and bandjoin" do
image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130]
split = image.bandsplit
x = split[0].bandjoin split[1..2]
expect(x[0].avg).to eq(100)
expect(x[1].avg).to eq(128)
expect(x[2].avg).to eq(130)
end
it "can bandjoin constants" do
image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130]
x = image.bandjoin 255
expect(x[0].avg).to eq(100)
expect(x[1].avg).to eq(128)
expect(x[2].avg).to eq(130)
expect(x[3].avg).to eq(255)
expect(x.bands).to eq(4)
x = image.bandjoin [1, 2]
expect(x[0].avg).to eq(100)
expect(x[1].avg).to eq(128)
expect(x[2].avg).to eq(130)
expect(x[3].avg).to eq(1)
expect(x[4].avg).to eq(2)
expect(x.bands).to eq(5)
end
it "can composite", version: [8, 6] do
image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130]
image = image.copy interpretation: :srgb
base = image + 10
overlay = image.bandjoin 128
comb = base.composite overlay, :over
pixel = comb.getpoint(0, 0)
expect(pixel[0]).to be_within(0.1).of(105)
expect(pixel[1]).to be_within(0.1).of(133)
expect(pixel[2]).to be_within(0.1).of(135)
expect(pixel[3]).to eq(255)
end
it "has minpos/maxpos" do
image = Vips::Image.black(16, 16) + 128
image = image.draw_rect 255, 10, 12, 1, 1
v, x, y = image.maxpos
expect(v).to eq(255)
expect(x).to eq(10)
expect(y).to eq(12)
image = Vips::Image.black(16, 16) + 128
image = image.draw_rect 12, 10, 12, 1, 1
v, x, y = image.minpos
expect(v).to eq(12)
expect(x).to eq(10)
expect(y).to eq(12)
end
it "can form complex images" do
r = Vips::Image.black(16, 16) + 128
i = Vips::Image.black(16, 16) + 12
cmplx = r.complexform i
re = cmplx.real
im = cmplx.imag
expect(re.avg).to eq(128)
expect(im.avg).to eq(12)
end
it "can convert complex polar <-> rectangular" do
r = Vips::Image.black(16, 16) + 128
i = Vips::Image.black(16, 16) + 12
cmplx = r.complexform i
cmplx = cmplx.rect.polar
expect(cmplx.real.avg).to be_within(0.001).of(128)
expect(cmplx.imag.avg).to be_within(0.001).of(12)
end
it "can take complex conjugate" do
r = Vips::Image.black(16, 16) + 128
i = Vips::Image.black(16, 16) + 12
cmplx = r.complexform i
cmplx = cmplx.conj
expect(cmplx.real.avg).to be_within(0.001).of(128)
expect(cmplx.imag.avg).to be_within(0.001).of(-12)
end
it "has working trig functions" do
image = Vips::Image.black(16, 16) + 67
image = image.sin.cos.tan
image = image.atan.acos.asin
expect(image.avg).to be_within(0.01).of(67)
end
it "has working log functions" do
image = Vips::Image.black(16, 16) + 67
image = image.log.exp.log10.exp10
expect(image.avg).to be_within(0.01).of(67)
end
it "can flip" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
b = Vips::Image.black(16, 16)
b = b.draw_rect 255, 15 - 10, 12, 1, 1
expect((a - b.fliphor).abs.max).to eq(0.0)
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 15 - 12, 1, 1
b = Vips::Image.black(16, 16)
b = b.draw_rect 255, 10, 12, 1, 1
expect((a - b.flipver).abs.max).to eq(0.0)
end
it "can getpoint" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
b = Vips::Image.black(16, 16)
b = b.draw_rect 255, 10, 10, 1, 1
im = a.bandjoin(b)
expect(im.getpoint(10, 12)).to eq([255, 0])
expect(im.getpoint(10, 10)).to eq([0, 255])
end
it "can median" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
im = a.median
expect(im.max).to eq(0)
end
it "can erode" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
mask = Vips::Image.new_from_array [
[128, 255, 128],
[255, 255, 255],
[128, 255, 128]
]
im = a.erode mask
expect(im.max).to eq(0)
end
it "can dilate" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
mask = Vips::Image.new_from_array [
[128, 255, 128],
[255, 255, 255],
[128, 255, 128]
]
im = a.dilate mask
expect(im.getpoint(10, 12)).to eq([255])
expect(im.getpoint(11, 12)).to eq([255])
expect(im.getpoint(12, 12)).to eq([0])
end
it "can rot" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
im = a.rot90.rot90.rot90.rot90
expect((a - im).abs.max).to eq(0.0)
im = a.rot180.rot180
expect((a - im).abs.max).to eq(0.0)
im = a.rot270.rot270.rot270.rot270
expect((a - im).abs.max).to eq(0.0)
end
it "can bandbool" do
a = Vips::Image.black(16, 16)
a = a.draw_rect 255, 10, 12, 1, 1
b = Vips::Image.black(16, 16)
b = b.draw_rect 255, 10, 10, 1, 1
im = a.bandjoin(b)
expect(im.bandand.getpoint(10, 12)).to eq([0])
expect(im.bandor.getpoint(10, 12)).to eq([255])
expect(im.bandeor.getpoint(10, 12)).to eq([255])
end
it "ifthenelse with image arguments" do
image = Vips::Image.black(16, 16)
image = image.draw_rect 255, 10, 12, 1, 1
black = Vips::Image.black(16, 16)
white = Vips::Image.black(16, 16) + 255
result = image.ifthenelse black, white
v, x, y = result.minpos
expect(v).to eq(0)
expect(x).to eq(10)
expect(y).to eq(12)
end
it "ifthenelse with constant arguments" do
image = Vips::Image.black(16, 16)
image = image.draw_rect 255, 10, 12, 1, 1
result = image.ifthenelse 0, 255
v, x, y = result.minpos
expect(v).to eq(0)
expect(x).to eq(10)
expect(y).to eq(12)
end
it "ifthenelse with vector arguments" do
image = Vips::Image.black(16, 16)
image = image.draw_rect 255, 10, 12, 1, 1
white = Vips::Image.black(16, 16) + 255
result = image.ifthenelse [255, 0, 0], white
v, x, y = result.minpos
expect(v).to eq(0)
expect(x).to eq(10)
expect(y).to eq(12)
end
it "has a #size method" do
image = Vips::Image.black(200, 100)
expect(image.size).to eq([image.width, image.height])
end
it "has #new_from_image method" do
image = Vips::Image.black(200, 100)
image2 = image.new_from_image 12
expect(image2.bands).to eq(1)
expect(image2.avg).to eq(12)
image2 = image.new_from_image [1, 2, 3]
expect(image2.bands).to eq(3)
expect(image2.avg).to eq(2)
end
it "can make interpolate objects" do
inter = Vips::Interpolate.new "bilinear"
expect(inter).not_to eq(nil)
end
it "can call affine with a non-default interpolator" do
image = Vips::Image.black(200, 100)
inter = Vips::Interpolate.new "bilinear"
result = image.affine [2, 0, 0, 2], interpolate: inter
expect(result.width).to eq(400)
expect(result.height).to eq(200)
end
it "has a working #to_a" do
image = Vips::Image.black(200, 100)
array = image.to_a
expect(array.length).to eq(100)
expect(array[0].length).to eq(200)
expect(array[0][0].length).to eq(1)
expect(array[0][0][0]).to eq(0)
end
it "supports keyword arguments" do
image = Vips::Image.black 200, 200, bands: 12
expect(image.width).to eq(200)
expect(image.height).to eq(200)
expect(image.bands).to eq(12)
end
if has_jpeg?
it "works with arguments containing -" do
image = Vips::Image.black(16, 16) + 128
buffer = image.write_to_buffer ".jpg", optimize_coding: true
expect(buffer.length).to be > 100
end
end
if has_jpeg?
it "can read exif tags" do
x = Vips::Image.new_from_file simg "huge.jpg"
orientation = x.get "exif-ifd0-Orientation"
expect(orientation.length).to be > 20
expect(orientation.split[0]).to eq("1")
end
end
# added in 8.5
if Vips.respond_to? :vips_image_get_fields
it "can read field names" do
x = Vips::Image.black 100, 100
y = x.get_fields
expect(y.length).to be > 10
expect(y[0]).to eq("width")
end
end
it "can has_alpha?" do
x = Vips::Image.new_from_file "./spec/samples/alpha.png"
expect(x.has_alpha?).to be true
end
it "can add_alpha", version: [8, 6] do
x = Vips::Image.new_from_file "./spec/samples/no_alpha.png"
expect(x.has_alpha?).to be false
y = x.add_alpha
expect(y.has_alpha?).to be true
end
end