diff --git a/.travis.yml b/.travis.yml index d3a4783..a8ea6ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: global: - VIPS_VERSION_MAJOR=8 - VIPS_VERSION_MINOR=5 - - VIPS_VERSION_MICRO=3 + - VIPS_VERSION_MICRO=8 - PATH=$HOME/vips/bin:$PATH - LD_LIBRARY_PATH=$HOME/vips/lib:$LD_LIBRARY_PATH - PKG_CONFIG_PATH=$HOME/vips/lib/pkgconfig:$PKG_CONFIG_PATH diff --git a/composer.json b/composer.json index 7b661cb..e0fde80 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,10 @@ "psr/log": "^1.0.1" }, "require-dev": { - "phpunit/phpunit": "^6.0", + "phpunit/phpunit": "^6.3", "phpdocumentor/phpdocumentor" : "^2.9", - "jakub-onderka/php-parallel-lint": "^0.9.2" + "jakub-onderka/php-parallel-lint": "^0.9.2", + "squizlabs/php_codesniffer": "3.*" }, "autoload": { "psr-4": { @@ -44,7 +45,8 @@ "scripts": { "test": [ "parallel-lint . --exclude vendor", - "phpunit" + "phpunit", + "phpcs --standard=phpcs-ruleset.xml ." ] } } diff --git a/examples/class.php b/examples/class.php index d156f0b..cedf97f 100755 --- a/examples/class.php +++ b/examples/class.php @@ -9,7 +9,7 @@ $image = Vips\Image::newFromFile($argv[1]); -echo "width = " . $image->width . "\n"; +echo 'width = ' . $image->width . "\n"; $image = $image->invert(); diff --git a/examples/sig.php b/examples/sig.php index 8f745bb..426890d 100755 --- a/examples/sig.php +++ b/examples/sig.php @@ -2,107 +2,153 @@ $ushort]); - # rescale so each element is in [0, 1] - $max = $lut->max(); - $lut = $lut->divide($max); - - # the sigmoidal equation, see - # - # http://www.imagemagick.org/Usage/color_mods/#sigmoidal - # - # though that's missing a term -- it should be - # - # (1/(1+exp(β*(α-u))) - 1/(1+exp(β*α))) / - # (1/(1+exp(β*(α-1))) - 1/(1+exp(β*α))) - # - # ie. there should be an extra α in the second term - $x = 1.0 / (1.0 + exp($beta * $alpha)); - $y = 1.0 / (1.0 + exp($beta * ($alpha - 1.0))) - $x; - $z = $lut->multiply(-1)->add($alpha)->multiply($beta)->exp()->add(1); - $result = $z->pow(-1)->subtract($x)->divide($y); - - # rescale back to 0 - 255 or 0 - 65535 - $result = $result->multiply($max); - - # and get the format right ... $result will be a float image after all - # that maths, but we want uchar or ushort - $result = $result->cast($ushort ? - Vips\BandFormat::USHORT : Vips\BandFormat::UCHAR); - + // Rescale so each element is in [0, 1] + $range = $lut->max(); + $lut = $lut->divide($range); + + /** + * The sigmoidal equation, see + * + * http://www.imagemagick.org/Usage/color_mods/#sigmoidal + * + * and + * + * http://osdir.com/ml/video.image-magick.devel/2005-04/msg00006.html + * + * Though that's missing a term -- it should be + * + * (1/(1+exp(β*(α-u))) - 1/(1+exp(β*α))) / + * (1/(1+exp(β*(α-1))) - 1/(1+exp(β*α))) + * + * ie. there should be an extra α in the second term + */ + if ($sharpen) { + $x = $lut->multiply(-1)->add($midpoint)->multiply($contrast)->exp()->add(1)->pow(-1); + $min = $x->min(); + $max = $x->max(); + $result = $x->subtract($min)->divide($max - $min); + } else { + $min = 1 / (1 + exp($contrast * $midpoint)); + $max = 1 / (1 + exp($contrast * ($midpoint - 1))); + $x = $lut->multiply($max - $min)->add($min); + $result = $x->multiply(-1)->add(1)->divide($x)->log()->divide($contrast)->multiply(-1)->add($midpoint); + } + + // Rescale back to 0 - 255 or 0 - 65535 + $result = $result->multiply($range); + + /** + * And get the format right ... $result will be a float image after all + * that maths, but we want uchar or ushort + */ + $result = $result->cast($ushort ? Vips\BandFormat::USHORT : Vips\BandFormat::UCHAR); return $result; } -# Apply to RGB. This takes no account of image gamma, and applies the -# contrast boost to R, G and B bands, thereby also boosting colourfulness. -function sigRGB(Vips\Image $image, float $alpha, float $beta): Vips\Image +/** + * Apply to RGB. This takes no account of image gamma, and applies the + * contrast boost to R, G and B bands, thereby also boosting colourfulness. + * + * @param Vips\Image $image The source image. + * @param bool $sharpen If true increase the contrast, if false decrease the contrast. + * @param float $midpoint Midpoint of the contrast (typically 0.5). + * @param float $contrast Strength of the contrast (typically 3-20). + * + * @return Vips\Image The manipulated image. + */ +function sigRGB(Vips\Image $image, bool $sharpen, float $midpoint, float $contrast): Vips\Image { - $lut = sigmoid($alpha, $beta, $image->format == Vips\BandFormat::USHORT); - + $lut = sigmoid($sharpen, $midpoint, $contrast, $image->format === Vips\BandFormat::USHORT); return $image->maplut($lut); } -# Fancier: apply to L of CIELAB. This will change luminance equally, and will -# not change colourfulness. -function sigLAB(Vips\Image $image, float $alpha, float $beta): Vips\Image +/** + * Fancier: apply to L of CIELAB. This will change luminance equally, and will + * not change colourfulness. + * + * @param Vips\Image $image The source image. + * @param bool $sharpen If true increase the contrast, if false decrease the contrast. + * @param float $midpoint Midpoint of the contrast (typically 0.5). + * @param float $contrast Strength of the contrast (typically 3-20). + * + * @return Vips\Image The manipulated image. + */ +function sigLAB(Vips\Image $image, bool $sharpen, float $midpoint, float $contrast): Vips\Image { - $old_interpretation = $image->interpretation; + $oldInterpretation = $image->interpretation; - # labs is CIELAB with colour values expressed as short (signed 16-bit ints) - # L is in 0 - 32767 + /** + * Labs is CIELAB with colour values expressed as short (signed 16-bit ints) + * L is in 0 - 32767 + */ $image = $image->colourspace(Vips\Interpretation::LABS); - # make a 16-bit LUT, then shrink by x2 to make it fit the range of L in labs - $lut = sigmoid($alpha, $beta, true); + // Make a 16-bit LUT, then shrink by x2 to make it fit the range of L in labs + $lut = sigmoid($sharpen, $midpoint, $contrast, true); $lut = $lut->shrinkh(2)->multiply(0.5); $lut = $lut->cast(Vips\BandFormat::SHORT); - # get the L band from our labs image, map though the LUT, then reattach the - # ab bands from the labs image + /** + * Get the L band from our labs image, map though the LUT, then reattach the + * ab bands from the labs image + */ $L = $image->extract_band(0); $AB = $image->extract_band(1, ['n' => 2]); $L = $L->maplut($lut); $image = $L->bandjoin($AB); - # and back to our original colourspace again (probably rgb) - # - # after the manipulation above, $image will just be tagged as a generic - # multiband image, vips will no longer know that it's a labs, so we need to - # tell colourspace what the source space is - $image = $image->colourspace( - $old_interpretation, - ['source_space' => Vips\Interpretation::LABS] - ); - - return $image; + /** + * And back to our original colourspace again (probably rgb) + * + * After the manipulation above, $image will just be tagged as a generic + * multiband image, vips will no longer know that it's a labs, so we need to + * tell colourspace what the source space is + */ + return $image->colourspace($oldInterpretation, [ + 'source_space' => Vips\Interpretation::LABS + ]); } $im = Vips\Image::newFromFile($argv[1], ['access' => Vips\Access::SEQUENTIAL]); -# $beta == 10 is a large contrast boost, values below about 4 drop the contrast -# -# sigLAB is the fancy one, and is much slower than sigRGB -$im = sigLAB($im, 0.5, 7); +/** + * $contrast == 10 is a large contrast boost, values below about 4 drop the contrast + * + * sigLAB is the fancy one, and is much slower than sigRGB + */ +$im = sigLAB($im, true, 0.5, 7); $im->writeToFile($argv[2]); diff --git a/phpcs-ruleset.xml b/phpcs-ruleset.xml new file mode 100644 index 0000000..fd567e0 --- /dev/null +++ b/phpcs-ruleset.xml @@ -0,0 +1,30 @@ + + + + php-vips coding standard. Inherits from PSR-2. + + + . + + + vendor/ + + + + + + + + + + + + + examples/ + + + + + src/ImageAutodoc.php + + diff --git a/src/Image.php b/src/Image.php index 1528e14..3c42479 100644 --- a/src/Image.php +++ b/src/Image.php @@ -1663,7 +1663,11 @@ public function bandjoin($other, array $options = []): Image { /* Allow a single unarrayed value as well. */ - $other = (array) $other; + if ($other instanceof Image) { + $other = [$other]; + } else { + $other = (array) $other; + } /* If $other is all numbers, we can use self::bandjoin_const(). */ @@ -1727,7 +1731,11 @@ public function bandrank($other, array $options = []): Image /* Allow a single unarrayed value as well. */ - $other = (array) $other; + if ($other instanceof Image) { + $other = [$other]; + } else { + $other = (array) $other; + } return self::call('bandrank', $this, $other, $options); } diff --git a/tests/call.php b/tests/CallTest.php similarity index 90% rename from tests/call.php rename to tests/CallTest.php index 39a7c5d..1406ec9 100644 --- a/tests/call.php +++ b/tests/CallTest.php @@ -1,8 +1,11 @@ 3]); + $image = Vips\Image::black(1, 4, ['bands' => 3]); $this->assertEquals($image->width, 1); $this->assertEquals($image->height, 4); @@ -45,7 +48,6 @@ public function testVipsDraw() $this->assertEquals($image->getpoint(0, 0), [0]); $this->assertEquals($image->getpoint(50, 50), [255]); } - } /* diff --git a/tests/Main.php b/tests/ConfigTest.php similarity index 87% rename from tests/Main.php rename to tests/ConfigTest.php index e0af5a8..861a5dd 100644 --- a/tests/Main.php +++ b/tests/ConfigTest.php @@ -1,8 +1,11 @@ image = Vips\Image::newFromFile($filename); $this->pixel = $this->image->getpoint(0, 0); } @@ -35,7 +38,7 @@ public function testVipsBandsplit() { $arr = $this->image->bandsplit(); - $this->assertEquals(count($arr), 3); + $this->assertCount(3, $arr); $this->assertEquals($arr[0]->bands, 1); } @@ -54,7 +57,7 @@ public function testVipsSubtractConst() $image = $image->subtract(1); $pixel = $image->getpoint(1, 1); - $this->assertEquals(count($pixel), 1); + $this->assertCount(1, $pixel); $this->assertEquals($pixel[0], 4); } @@ -64,7 +67,7 @@ public function testVipsMultiplyConst() $image = $image->multiply(2); $pixel = $image->getpoint(1, 1); - $this->assertEquals(count($pixel), 1); + $this->assertCount(1, $pixel); $this->assertEquals($pixel[0], 10); } @@ -74,7 +77,7 @@ public function testVipsDivideConst() $image = $image->divide(2); $pixel = $image->getpoint(0, 1); - $this->assertEquals(count($pixel), 1); + $this->assertCount(1, $pixel); $this->assertEquals($pixel[0], 2); } @@ -144,7 +147,6 @@ public function testVipsMedian() $this->assertEquals($result, [37, 38, 33]); } - } /* diff --git a/tests/exception.php b/tests/ExceptionTest.php similarity index 90% rename from tests/exception.php rename to tests/ExceptionTest.php index a898a94..b38c43b 100644 --- a/tests/exception.php +++ b/tests/ExceptionTest.php @@ -1,8 +1,11 @@ image = Vips\Image::newFromFile($filename); $this->pixel = $this->image->getpoint(0, 0); } @@ -55,7 +58,6 @@ public function testVipsOperationException() $x = $this->image->add([1, 2, 3, 4]); } - } /* diff --git a/tests/logger.php b/tests/LoggerTest.php similarity index 56% rename from tests/logger.php rename to tests/LoggerTest.php index 6154560..ea79e67 100644 --- a/tests/logger.php +++ b/tests/LoggerTest.php @@ -1,8 +1,13 @@ assertInstanceOf(Psr\Log\LoggerInterface::class, $logger); + $this->assertInstanceOf(LoggerInterface::class, $logger); } - } /* diff --git a/tests/meta.php b/tests/MetaTest.php similarity index 83% rename from tests/meta.php rename to tests/MetaTest.php index 20eba00..9fd3cb5 100644 --- a/tests/meta.php +++ b/tests/MetaTest.php @@ -1,8 +1,11 @@ image = Vips\Image::newFromFile($filename); - $png_filename = dirname(__FILE__) . '/images/PNG_transparency_demonstration_1.png'; + $png_filename = __DIR__ . '/images/PNG_transparency_demonstration_1.png'; $this->png_image = Vips\Image::newFromFile($png_filename); } @@ -76,10 +79,9 @@ public function testVipsEnumString() public function testVipsHasAlpha() { - $this->assertEquals($this->image->hasAlpha(), FALSE); - $this->assertEquals($this->png_image->hasAlpha(), TRUE); + $this->assertEquals($this->image->hasAlpha(), false); + $this->assertEquals($this->png_image->hasAlpha(), true); } - } /* diff --git a/tests/new.php b/tests/NewTest.php similarity index 84% rename from tests/new.php rename to tests/NewTest.php index 1771c83..7e41e6f 100644 --- a/tests/new.php +++ b/tests/NewTest.php @@ -1,8 +1,11 @@ assertEquals($image->width, 1600); @@ -33,7 +36,7 @@ public function testVipsNewFromFile() public function testVipsNewFromImage() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $image = Vips\Image::newFromFile($filename); $image2 = $image->newFromImage(12); @@ -48,7 +51,7 @@ public function testVipsNewFromImage() $this->assertEquals($image2->bands, 1); $this->assertEquals($image2->avg(), 12); - $image2 = $image->newFromImage([1,2,3]); + $image2 = $image->newFromImage([1, 2, 3]); $this->assertEquals($image2->bands, 3); $this->assertEquals($image2->avg(), 2); @@ -56,7 +59,7 @@ public function testVipsNewFromImage() public function testVipsFindLoad() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $loader = Vips\Image::findLoad($filename); $this->assertEquals($loader, 'VipsForeignLoadJpegFile'); @@ -64,7 +67,7 @@ public function testVipsFindLoad() public function testVipsNewFromBuffer() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $buffer = file_get_contents($filename); $image = Vips\Image::newFromBuffer($buffer); @@ -75,7 +78,7 @@ public function testVipsNewFromBuffer() public function testVipsFindLoadBuffer() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $buffer = file_get_contents($filename); $loader = Vips\Image::findLoadBuffer($buffer); @@ -84,7 +87,7 @@ public function testVipsFindLoadBuffer() public function testVipsCopyMemory() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $image1 = Vips\Image::newFromFile($filename); $image2 = $image1->copyMemory(); @@ -93,7 +96,7 @@ public function testVipsCopyMemory() public function testVipsNewInterpolator() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $image1 = Vips\Image::newFromFile($filename); $interp = Vips\Image::newInterpolator('bicubic'); $image2 = $image1->affine([2, 0, 0, 2], ['interpolate' => $interp]); @@ -104,7 +107,6 @@ public function testVipsNewInterpolator() $this->assertNotNull($interp); $this->assertEquals($widthInput * 2, $widthOutput); } - } /* diff --git a/tests/shortcuts.php b/tests/ShortcutTest.php similarity index 68% rename from tests/shortcuts.php rename to tests/ShortcutTest.php index f2bc3e3..d66798c 100644 --- a/tests/shortcuts.php +++ b/tests/ShortcutTest.php @@ -1,8 +1,11 @@ image = Vips\Image::newFromFile($filename, ['shrink' => 8]); $this->pixel = $this->image->getpoint(0, 0); } public function testVipsPow() { - $real = self::map_numeric($this->pixel, function ($value) { - return $value ** 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value ** 2; }); $vips = $this->image->pow(2)->getpoint(0, 0); @@ -47,8 +49,8 @@ public function testVipsPow() public function testVipsWop() { - $real = self::map_numeric($this->pixel, function ($value) { - return 2 ** $value; + $real = self::mapNumeric($this->pixel, function ($value) { + return 2 ** $value; }); $vips = $this->image->wop(2)->getpoint(0, 0); @@ -57,144 +59,106 @@ public function testVipsWop() public function testVipsRemainder() { - $real = self::map_numeric($this->pixel, function ($value) { - return $value % 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value % 2; }); $vips = $this->image->remainder(2)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - return $value % $value; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value % $value; }); $vips = $this->image->remainder($this->image)->getpoint(0, 0); $this->assertEquals($vips, $real); - } public function testVipsShift() { - $real = self::map_numeric($this->pixel, function ($value) { - return $value << 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value << 2; }); $vips = $this->image->lshift(2)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - return $value >> 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value >> 2; }); $vips = $this->image->rshift(2)->getpoint(0, 0); $this->assertEquals($vips, $real); - } public function testVipsBool() { - $real = self::map_numeric($this->pixel, function ($value) { - return $value & 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value & 2; }); $vips = $this->image->andimage(2)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - return $value | 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value | 2; }); $vips = $this->image->orimage(2)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - return $value ^ 2; + $real = self::mapNumeric($this->pixel, function ($value) { + return $value ^ 2; }); $vips = $this->image->eorimage(2)->getpoint(0, 0); $this->assertEquals($vips, $real); - } public function testVipsRelational() { - $real = self::map_numeric($this->pixel, function ($value) { - if ($value > 38) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + return $value > 38 ? 255 : 0; }); $vips = $this->image->more(38)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - if ($value >= 38) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + return $value >= 38 ? 255 : 0; }); - $vips = $this->image->moreeq(38)->getpoint(0, 0); + $vips = $this->image->moreEq(38)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - if ($value > $value) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + // $value > $value is always false + return 0; }); $vips = $this->image->more($this->image)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - if ($value < 38) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + return $value < 38 ? 255 : 0; }); $vips = $this->image->less(38)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - if ($value <= 38) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + return $value <= 38 ? 255 : 0; }); - $vips = $this->image->lesseq(38)->getpoint(0, 0); + $vips = $this->image->lessEq(38)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - if ($value == 38) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + return $value === 38 ? 255 : 0; }); $vips = $this->image->equal(38)->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($this->pixel, function ($value) { - if ($value != 38) { - return 255; - } - else { - return 0; - } + $real = self::mapNumeric($this->pixel, function ($value) { + return $value !== 38 ? 255 : 0; }); - $vips = $this->image->noteq(38)->getpoint(0, 0); + $vips = $this->image->notEq(38)->getpoint(0, 0); $this->assertEquals($vips, $real); - } public function testVipsRound() @@ -202,31 +166,30 @@ public function testVipsRound() $image = $this->image->add([0.1, 1.4, 0.9]); $pixel = $image->getpoint(0, 0); - $real = self::map_numeric($pixel, function ($value) { + $real = self::mapNumeric($pixel, function ($value) { return floor($value); }); $vips = $image->floor()->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($pixel, function ($value) { + $real = self::mapNumeric($pixel, function ($value) { return ceil($value); }); $vips = $image->ceil()->getpoint(0, 0); $this->assertEquals($vips, $real); - $real = self::map_numeric($pixel, function ($value) { + $real = self::mapNumeric($pixel, function ($value) { return round($value); }); $vips = $image->rint()->getpoint(0, 0); $this->assertEquals($vips, $real); - } public function testVipsBandand() { $real = $this->pixel[0] & $this->pixel[1] & $this->pixel[2]; $vips = $this->image->bandand()->getpoint(0, 0); - $this->assertEquals(count($vips), 1); + $this->assertCount(1, $vips); $this->assertEquals($vips[0], $real); } @@ -283,7 +246,6 @@ public function testOffsetSet() $this->assertEquals($test[1]->avg(), 3); $this->assertEquals($test[2]->avg(), 4); $this->assertEquals($test[3]->avg(), 12); - } public function testOffsetUnset() @@ -319,7 +281,6 @@ public function testOffsetUnset() $this->assertEquals($test[0]->avg(), 2); $this->assertEquals($test[1]->avg(), 3); $this->assertEquals($test[2]->avg(), 4); - } public function testOffsetUnsetAll() @@ -328,7 +289,7 @@ public function testOffsetUnsetAll() // remove all $test = $base->copy(); - $this->expectException(BadMethodCallException::class); + $this->expectException(\BadMethodCallException::class); unset($test[0]); } } diff --git a/tests/write.php b/tests/WriteTest.php similarity index 77% rename from tests/write.php rename to tests/WriteTest.php index c082fc8..b581976 100644 --- a/tests/write.php +++ b/tests/WriteTest.php @@ -1,27 +1,30 @@ tmps = []; } - function tearDown() + protected function tearDown() { foreach ($this->tmps as $tmp) { - @unlink($tmp); + @unlink($tmp); } } - function tmp($suffix) + public function tmp($suffix) { $tmp = tempnam(sys_get_temp_dir(), 'vips-test'); unlink($tmp); @@ -33,7 +36,7 @@ function tmp($suffix) public function testVipsWriteToFile() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $image = Vips\Image::newFromFile($filename, ['shrink' => 8]); $output_filename = $this->tmp('.jpg'); $image->writeToFile($output_filename); @@ -46,7 +49,7 @@ public function testVipsWriteToFile() public function testVipsWriteToBuffer() { - $filename = dirname(__FILE__) . '/images/img_0076.jpg'; + $filename = __DIR__ . '/images/img_0076.jpg'; $image = Vips\Image::newFromFile($filename, ['shrink' => 8]); $buffer1 = $image->writeToBuffer('.jpg'); @@ -54,9 +57,8 @@ public function testVipsWriteToBuffer() $image->writeToFile($output_filename); $buffer2 = file_get_contents($output_filename); - $this->assertEquals($buffer1, $buffer2); + $this->assertEquals($buffer1, $buffer2); } - } /*