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


PHP ImageInterface::getColorAt方法代码示例

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


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

示例1: apply

 /**
  * Applies scheduled transformation to ImageInterface instance
  * Returns processed ImageInterface instance
  *
  * @param \Imagine\Image\ImageInterface $image
  *
  * @return \Imagine\Image\ImageInterface
  */
 function apply(ImageInterface $image)
 {
     // We reduce the usage of methods on the image to dramatically increase the performance of this algorithm.
     // Really... We need that performance...
     // Therefore we first build a matrix, that holds the colors of the image.
     $width = $image->getSize()->getWidth();
     $height = $image->getSize()->getHeight();
     $byteData = new Matrix($width, $height);
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $byteData->setElementAt($x, $y, $image->getColorAt(new Point($x, $y)));
         }
     }
     $dHeight = (int) floor(($this->matrix->getHeight() - 1) / 2);
     $dWidth = (int) floor(($this->matrix->getWidth() - 1) / 2);
     for ($y = $dHeight; $y < $height - $dHeight; $y++) {
         for ($x = $dWidth; $x < $width - $dWidth; $x++) {
             $sumRed = 0;
             $sumGreen = 0;
             $sumBlue = 0;
             // calculate new color
             for ($boxX = $x - $dWidth, $matrixX = 0; $boxX <= $x + $dWidth; $boxX++, $matrixX++) {
                 for ($boxY = $y - $dHeight, $matrixY = 0; $boxY <= $y + $dHeight; $boxY++, $matrixY++) {
                     $sumRed = $sumRed + $this->matrix->getElementAt($matrixX, $matrixY) * $byteData->getElementAt($boxX, $boxY)->getRed();
                     $sumGreen = $sumGreen + $this->matrix->getElementAt($matrixX, $matrixY) * $byteData->getElementAt($boxX, $boxY)->getGreen();
                     $sumBlue = $sumBlue + $this->matrix->getElementAt($matrixX, $matrixY) * $byteData->getElementAt($boxX, $boxY)->getBlue();
                 }
             }
             // set new color - has to be between 0 and 255!
             $image->draw()->dot(new Point($x, $y), new Color(array('red' => max(0, min(255, $sumRed)), 'green' => max(0, min(255, $sumGreen)), 'blue' => max(0, min(255, $sumBlue)))));
         }
     }
     return $image;
 }
开发者ID:rejinka,项目名称:imagine-extra,代码行数:42,代码来源:Neighborhood.php

示例2: load

 /**
  * @see Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface::load()
  */
 public function load(ImageInterface $image, array $options = array())
 {
     $size = $image->getSize();
     $width = $size->getWidth();
     $height = $size->getHeight();
     $alpha = $options['opacity'];
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $point = new Point($x, $y);
             $color = $image->getColorAt($point);
             $dR = $color->getRed();
             $dG = $color->getGreen();
             $dB = $color->getBlue();
             $image->draw()->dot($point, new Color(array($dR, $dG, $dB), $alpha));
         }
     }
     return $image;
 }
开发者ID:symbb,项目名称:symbb,代码行数:21,代码来源:OpacityFilterLoader.php

示例3: applyMask

 /**
  * {@inheritdoc}
  */
 public function applyMask(ImageInterface $mask)
 {
     if (!$mask instanceof self) {
         throw new InvalidArgumentException('Cannot mask non-gd images');
     }
     $size = $this->getSize();
     $maskSize = $mask->getSize();
     if ($size != $maskSize) {
         throw new InvalidArgumentException(sprintf('The given mask doesn\'t match current image\'s size, Current ' . 'mask\'s dimensions are %s, while image\'s dimensions are %s', $maskSize, $size));
     }
     for ($x = 0, $width = $size->getWidth(); $x < $width; $x++) {
         for ($y = 0, $height = $size->getHeight(); $y < $height; $y++) {
             $position = new Point($x, $y);
             $color = $this->getColorAt($position);
             $maskColor = $mask->getColorAt($position);
             $round = (int) round(max($color->getAlpha(), (100 - $color->getAlpha()) * $maskColor->getRed() / 255));
             if (false === imagesetpixel($this->resource, $x, $y, $this->getColor($color->dissolve($round - $color->getAlpha())))) {
                 throw new RuntimeException('Apply mask operation failed');
             }
         }
     }
     return $this;
 }
开发者ID:jewelhuq,项目名称:fraym,代码行数:26,代码来源:Image.php


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