(PECL imagick >= 3.3.0)
ImagickKernel::scale — 按给定量缩放内核列表
按给定量缩放给定的内核列表,并根据给定的标志进行或不进行内核值总和的标准化。此函数的确切行为取决于所使用的标准化类型,请参阅 https://imagemagick.org.cn/api/morphology.php#ScaleKernelInfo 以获取详细信息。
scale
normalizeFlag
示例 #1 ImagickKernel::scale()
<?php
function renderKernelTable($matrix) {
$output = "<table class='infoTable'>";
foreach ($matrix as $row) {
$output .= "<tr>";
foreach ($row as $cell) {
$output .= "<td style='text-align:left'>";
if ($cell === false) {
$output .= "false";
}
else {
$output .= round($cell, 3);
}
$output .= "</td>";
}
$output .= "</tr>";
}
$output .= "</table>";
return $output;
}
$output = "";
$matrix = [
[-1, 0, -1],
[ 0, 4, 0],
[-1, 0, -1],
];
$kernel = \ImagickKernel::fromMatrix($matrix);
$kernelClone = clone $kernel;
$output .= "开始内核<br/>";
$output .= renderKernelTable($kernel->getMatrix());
$output .= "使用 NORMALIZE_KERNEL_VALUE 进行缩放。<br/>";
$kernel->scale(2, \Imagick::NORMALIZE_KERNEL_VALUE);
$output .= renderKernelTable($kernel->getMatrix());
$kernel = clone $kernelClone;
$output .= "按百分比缩放<br/>";
$kernel->scale(2, \Imagick::NORMALIZE_KERNEL_PERCENT);
$output .= renderKernelTable($kernel->getMatrix());
$matrix2 = [
[-1, -1, 1],
[ -1, false, 1],
[1, 1, 1],
];
$kernel = \ImagickKernel::fromMatrix($matrix2);
$output .= "按相关性缩放<br/>";
$kernel->scale(1, \Imagick::NORMALIZE_KERNEL_CORRELATE);
$output .= renderKernelTable($kernel->getMatrix());
return $output;
?>