ImagickKernel::separate()函數是PHP中的內置函數,用於分隔一組鏈接的內核並返回ImagickKernels數組。此函數用於計算對象中的內核或查看對象的內核。
用法:
array ImagickKernel::separate( void )
參數:此函數不接受任何參數。
返回值:此函數返回包含ImagickKernels的數組值。
以下示例程序旨在說明PHP中的ImagickKernel::separate()函數:
程序1:該程序計算ImagickKernel中的所有內核。
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
$matrix1 = [
[-1, -1, -1],
[4, 4, 4],
[1, 1, 1],
];
$matrix2 = [
[-1, 0, 0],
[0, 0, 1],
[-1, 0, 1],
];
$matrix3 = [
[-1, 1, 0],
[0, 0, 1],
[-1, 0, 1],
];
$matrix4 = [
[0, 1, 0],
[0, 0, 1],
[-1, 0, 1],
];
// Create ImagickKernel objects from matrices
$kernel1 = ImagickKernel::fromMatrix($matrix1);
$kernel2 = ImagickKernel::fromMatrix($matrix2);
$kernel3 = ImagickKernel::fromMatrix($matrix3);
$kernel4 = ImagickKernel::fromMatrix($matrix4);
// Add the kernels
$kernel1->addKernel($kernel2);
$kernel1->addKernel($kernel3);
$kernel1->addKernel($kernel4);
$kernelList = $kernel1->separate();
echo 'Total number of attached kernels are:';
echo count($kernelList);
?>
輸出:
Total number of attached kernels are:4
程序2(將所有ImagickKernel獲取到一個對象中):
<?php
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
$matrix1 = [
[-1, -1, -1],
[4, 4, 4],
[1, 1, 1],
];
$matrix2 = [
[-1, 0, 0],
[0, 0, 1],
[-1, 0, 1],
];
// Create ImagickKernel objects from matrices
$kernel1 = ImagickKernel::fromMatrix($matrix1);
$kernel2 = ImagickKernel::fromMatrix($matrix2);
// Add the kernel
$kernel1->addKernel($kernel2);
$kernelList = $kernel1->separate();
echo 'All the kernels are:';
print("<pre>".print_r($kernelList, true)."</pre>");
?>
輸出:
All the kernels are: Array ( [0] => ImagickKernel Object ( [0] => Array ( [0] => Array ( [0] => -1 [1] => -1 [2] => -1 ) [1] => Array ( [0] => 4 [1] => 4 [2] => 4 ) [2] => Array ( [0] => 1 [1] => 1 [2] => 1 ) ) ) [1] => ImagickKernel Object ( [0] => Array ( [0] => Array ( [0] => -1 [1] => 0 [2] => 0 ) [1] => Array ( [0] => 0 [1] => 0 [2] => 1 ) [2] => Array ( [0] => -1 [1] => 0 [2] => 1 ) ) ) )
參考: https://www.php.net/manual/en/imagickkernel.separate.php
相關用法
- PHP ImagickKernel fromMatrix()用法及代碼示例
- PHP ImagickKernel addKernel()用法及代碼示例
- PHP ImagickKernel getMatrix()用法及代碼示例
- PHP ImagickKernel addUnityKernel()用法及代碼示例
- PHP ImagickKernel scale()用法及代碼示例
- PHP ImagickKernel fromBuiltIn()用法及代碼示例
- PHP pow( )用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- PHP Ds\Set sum()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | ImagickKernel separate() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。