|
| 1 | +<?php |
| 2 | + |
| 3 | +use Vips\Image\Image; |
| 4 | + |
| 5 | +class VipsCallTest extends PHPUnit_Framework_TestCase |
| 6 | +{ |
| 7 | + |
| 8 | + public function testVipsCall() |
| 9 | + { |
| 10 | + $image = Image::newFromArray([1, 2, 3]); |
| 11 | + $image = $image->embed(10, 20, 3000, 2000, ["extend" => "copy"]); |
| 12 | + |
| 13 | + $this->assertEquals($image->width, 3000); |
| 14 | + $this->assertEquals($image->height, 2000); |
| 15 | + $this->assertEquals($image->bands, 1); |
| 16 | + } |
| 17 | + |
| 18 | + public function testVipsCallStatic() |
| 19 | + { |
| 20 | + $image = Image::black(1, 2, ["bands" => 3]); |
| 21 | + |
| 22 | + $this->assertEquals($image->width, 1); |
| 23 | + $this->assertEquals($image->height, 2); |
| 24 | + $this->assertEquals($image->bands, 3); |
| 25 | + } |
| 26 | + |
| 27 | + public function testVipsBandjoin() |
| 28 | + { |
| 29 | + $image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]); |
| 30 | + $rgb = $image->bandjoin([$image, $image]); |
| 31 | + |
| 32 | + $this->assertEquals($rgb->width, 3); |
| 33 | + $this->assertEquals($rgb->height, 2); |
| 34 | + $this->assertEquals($rgb->bands, 3); |
| 35 | + } |
| 36 | + |
| 37 | + public function testVipsAddConst() |
| 38 | + { |
| 39 | + $image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]); |
| 40 | + $image = $image->add(1); |
| 41 | + $pixel = $image->crop(0, 0, 1, 1)->avg(); |
| 42 | + |
| 43 | + $this->assertEquals($pixel, 2); |
| 44 | + } |
| 45 | + |
| 46 | + public function testVipsGetPoint() |
| 47 | + { |
| 48 | + $image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]); |
| 49 | + $rgb = $image->bandjoin([$image, $image]); |
| 50 | + $rgb = $rgb->add(1); |
| 51 | + $pixel = $rgb->getpoint(0, 0); |
| 52 | + |
| 53 | + $this->assertEquals($pixel, [2, 2, 2]); |
| 54 | + } |
| 55 | + |
| 56 | + public function testVipsBandjoinConst() |
| 57 | + { |
| 58 | + $image = Image::newFromArray([[1, 2, 3], [4, 5, 6]]); |
| 59 | + $imagea = $image->bandjoin(255); |
| 60 | + $pixel = $imagea->getpoint(0, 0); |
| 61 | + |
| 62 | + $this->assertEquals($pixel, [1, 255]); |
| 63 | + } |
| 64 | + |
| 65 | + public function testVipsIfthenelseConst() |
| 66 | + { |
| 67 | + $filename = dirname(__FILE__) . "/images/img_0076.jpg"; |
| 68 | + $image = Image::newFromFile($filename); |
| 69 | + |
| 70 | + $if = $image->more(34)->ifthenelse(255, $image); |
| 71 | + $pixel = $if->getpoint(0, 0); |
| 72 | + $this->assertEquals($pixel, [255, 255, 34]); |
| 73 | + |
| 74 | + $if = $image->more(34)->ifthenelse($image, 255); |
| 75 | + $pixel = $if->getpoint(0, 0); |
| 76 | + $this->assertEquals($pixel, [39, 38, 255]); |
| 77 | + |
| 78 | + $if = $image->more(34)->ifthenelse(128, 255); |
| 79 | + $pixel = $if->getpoint(0, 0); |
| 80 | + $this->assertEquals($pixel, [128, 128, 255]); |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | +} |
0 commit comments