diff --git a/ImagickKernel.stub.php b/ImagickKernel.stub.php index 043cd13b..3a5f7ed8 100644 --- a/ImagickKernel.stub.php +++ b/ImagickKernel.stub.php @@ -15,7 +15,7 @@ public function addUnityKernel(float $scale): void {} // KERNEL_* public static function fromBuiltin(int $kernel, string $shape): ImagickKernel {} - public static function fromMatrix(array $matrix, array $origin = null): ImagickKernel {} + public static function fromMatrix(array $matrix, ?array $origin = null): ImagickKernel {} public function getMatrix(): array {} diff --git a/ImagickKernel_arginfo.h b/ImagickKernel_arginfo.h index f74a1f19..57129332 100644 --- a/ImagickKernel_arginfo.h +++ b/ImagickKernel_arginfo.h @@ -70,7 +70,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ImagickKernel_fromMatrix, 0, 0, 1) #endif #if PHP_VERSION_ID >= 80000 - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, origin, IS_ARRAY, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, origin, IS_ARRAY, 1, "null") #else ZEND_ARG_INFO(0, origin) #endif diff --git a/imagickkernel_class.c b/imagickkernel_class.c index eee111ac..4d8b7cb0 100644 --- a/imagickkernel_class.c +++ b/imagickkernel_class.c @@ -233,7 +233,6 @@ PHP_METHOD(ImagickKernel, __construct) */ #if PHP_VERSION_ID >= 70000 PHP_METHOD(ImagickKernel, fromMatrix) - { zval *kernel_array; zval *origin_array; @@ -257,7 +256,7 @@ PHP_METHOD(ImagickKernel, fromMatrix) row = 0; origin_array = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|a", &kernel_array, &origin_array) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|a!", &kernel_array, &origin_array) == FAILURE) { RETURN_THROWS(); } diff --git a/tests/145_imagickkernel_coverage.phpt b/tests/145_imagickkernel_coverage.phpt index 37de74b2..a511c41e 100644 --- a/tests/145_imagickkernel_coverage.phpt +++ b/tests/145_imagickkernel_coverage.phpt @@ -204,6 +204,25 @@ if ($kernelMatrix !== $matrix) { var_dump($kernelMatrix); } + + + +//Test Scaling, and with null origin +$matrixIn = array( + array(-1, 0, -1), + array( 0, 8, 0), + array(-1, 0, -1), +); +$kernel = ImagickKernel::fromMatrix($matrixIn, null); // <-- line under test +$kernel->scale(1, \Imagick::NORMALIZE_KERNEL_VALUE); +$matrixOut = $kernel->getMatrix(); + +if ($matrixOut[1][1] != 2) { + echo "Matrix was not normalised correctly."; + var_dump($matrixOut); +} + + echo "Complete".PHP_EOL; ?> --EXPECTF--