/**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $width = $aResource->getX();
     $height = $aResource->getY();
     $blockImg = imagecreate(1, 1);
     imagecolorallocatealpha($blockImg, $this->blockColor->getRed(), $this->blockColor->getGreen(), $this->blockColor->getBlue(), $this->blockColor->getAlpha());
     for ($i = 0; $i <= $this->nrOfBlocks; $i++) {
         $xPos = rand(0, $width - $this->blockSize - 1);
         $yPos = rand(0, $height - $this->blockSize - 1);
         imagecopy($aResource->getResource(), $blockImg, $xPos, $yPos, $xPos, $yPos, $this->blockSize, $this->blockSize);
     }
 }
 /**
  * Generate a gradient image
  * 
  * @param int $width The new image width in pixels
  * @param int $height The new image height in pixels
  * @param int $start The start of the gradient in pixels
  * @param Color $src_color The start image color
  * @param Color $dest_color The end image color
  * 
  * @return \imagemanipulation\ImageResource
  */
 public static function gradient($width, $height, $start, Color $src_color, Color $dest_color)
 {
     Args::int($width, 'width')->required()->min(1);
     Args::int($height, 'height')->required()->min(1);
     $res = self::create($width, $height, $src_color);
     $img = $res->getResource();
     $srcA = $src_color->getAlpha();
     $srcR = $src_color->getRed();
     $srcG = $src_color->getGreen();
     $srcB = $src_color->getBlue();
     $destA = $dest_color->getAlpha();
     $destR = $dest_color->getRed();
     $destG = $dest_color->getGreen();
     $destB = $dest_color->getBlue();
     $incA = ($destA - $srcA) / ($width - $start);
     $incR = ($destR - $srcR) / ($width - $start);
     $incG = ($destG - $srcG) / ($width - $start);
     $incB = ($destB - $srcB) / ($width - $start);
     for ($i = $start; $i < $width; $i++) {
         $srcA += $incA;
         $srcB += $incB;
         $srcG += $incG;
         $srcR += $incR;
         imagefilledrectangle($img, $i, 0, $i, $height, imagecolorallocatealpha($img, $srcR, $srcG, $srcB, $srcA));
     }
     return $res;
 }
Esempio n. 3
0
 private function checkColorDDD(Color $aColor)
 {
     $this->assertEquals(221, $aColor->getRed(), 'Checking red');
     $this->assertEquals(221, $aColor->getGreen(), 'Checking green');
     $this->assertEquals(221, $aColor->getBlue(), 'Checking blue');
     $this->assertEquals(127, $aColor->getAlpha(), 'Checking alpha');
     $this->assertEquals('dddddd', $aColor->getHexColor(), 'Checking hex color code');
     $this->assertEquals(2145246685, $aColor->getColorIndex(), 'Checking color index');
 }
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     $dest = $aResource->getResource();
     if (imageistruecolor($dest)) {
         imagetruecolortopalette($dest, false, 256);
     }
     foreach ($this->search as $search) {
         $searchRgb = new Color($search);
         $index = imagecolorclosest($aResource->getResource(), $searchRgb->getRed(), $searchRgb->getGreen(), $searchRgb->getBlue());
         // get White COlor
         imagecolorset($aResource->getResource(), $index, $this->replace->getRed(), $this->replace->getGreen(), $this->replace->getBlue());
         // SET NEW COLOR
     }
     $aResource->setResource($dest);
 }
Esempio n. 5
0
 /**
  * Returns the allocated color
  *
  * @param RGBColor $aColor
  * @return int
  */
 public static function allocateColor($aImgRes, Color $aColor)
 {
     return imagecolorallocatealpha($aImgRes, $aColor->getRed(), $aColor->getGreen(), $aColor->getBlue(), $aColor->getAlpha());
 }