当前位置: 首页>>代码示例>>PHP>>正文


PHP WideImage_Image::applyConvolution方法代码示例

本文整理汇总了PHP中WideImage_Image::applyConvolution方法的典型用法代码示例。如果您正苦于以下问题:PHP WideImage_Image::applyConvolution方法的具体用法?PHP WideImage_Image::applyConvolution怎么用?PHP WideImage_Image::applyConvolution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WideImage_Image的用法示例。


在下文中一共展示了WideImage_Image::applyConvolution方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Returns sharpened image
  *
  * @param WideImage_Image $image
  * @param float $amount
  * @param int $radius
  * @param float $threshold
  * @return WideImage_Image
  */
 function execute($image, $amount, $radius, $threshold)
 {
     // Attempt to calibrate the parameters to Photoshop:
     if ($amount > 500) {
         $amount = 500;
     }
     $amount = $amount * 0.016;
     if ($radius > 50) {
         $radius = 50;
     }
     $radius = $radius * 2;
     if ($threshold > 255) {
         $threshold = 255;
     }
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return $image;
     }
     // Gaussian blur matrix
     $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1));
     $blurred = $image->applyConvolution($matrix, 16, 0);
     if ($threshold > 0) {
         // Calculate the difference between the blurred pixels and the original
         // and set the pixels
         for ($x = 0; $x < $image->getWidth(); $x++) {
             for ($y = 0; $y < $image->getHeight(); $y++) {
                 $rgbOrig = $image->getRGBAt($x, $y);
                 $rOrig = $rgbOrig["red"];
                 $gOrig = $rgbOrig["green"];
                 $bOrig = $rgbOrig["blue"];
                 $rgbBlur = $blurred->getRGBAt($x, $y);
                 $rBlur = $rgbBlur["red"];
                 $gBlur = $rgbBlur["green"];
                 $bBlur = $rgbBlur["blue"];
                 // When the masked pixels differ less from the original
                 // than the threshold specifies, they are set to their original value.
                 $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
                 $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
                 $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
                 $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0);
                 if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                     $image->setRGBAt($x, $y, $rgbNew);
                 }
             }
         }
     } else {
         $w = $image->getWidth();
         $h = $image->getHeight();
         for ($x = 0; $x < $w; $x++) {
             for ($y = 0; $y < $h; $y++) {
                 $rgbOrig = $image->getRGBAt($x, $y);
                 $rOrig = $rgbOrig["red"];
                 $gOrig = $rgbOrig["green"];
                 $bOrig = $rgbOrig["blue"];
                 $rgbBlur = $blurred->getRGBAt($x, $y);
                 $rBlur = $rgbBlur["red"];
                 $gBlur = $rgbBlur["green"];
                 $bBlur = $rgbBlur["blue"];
                 $rNew = $amount * ($rOrig - $rBlur) + $rOrig;
                 if ($rNew > 255) {
                     $rNew = 255;
                 } elseif ($rNew < 0) {
                     $rNew = 0;
                 }
                 $gNew = $amount * ($gOrig - $gBlur) + $gOrig;
                 if ($gNew > 255) {
                     $gNew = 255;
                 } elseif ($gNew < 0) {
                     $gNew = 0;
                 }
                 $bNew = $amount * ($bOrig - $bBlur) + $bOrig;
                 if ($bNew > 255) {
                     $bNew = 255;
                 } elseif ($bNew < 0) {
                     $bNew = 0;
                 }
                 $rgbNew = array("red" => $rNew, "green" => $gNew, "blue" => $bNew, "alpha" => 0);
                 $image->setRGBAt($x, $y, $rgbNew);
             }
         }
     }
     return $image;
 }
开发者ID:ehazell,项目名称:AZDWR,代码行数:93,代码来源:Unsharp.php


注:本文中的WideImage_Image::applyConvolution方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。