/** * 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); } }
/** * Applies the filter to the image resource * * @param ImageResource $aResource */ public function applyFilter(ImageResource $aResource) { if ($this->angle == 0 || $this->angle == 360) { return; } imageantialias($aResource->getResource(), true); $aResource->setResource(imagerotate($aResource->getResource(), $this->angle, $this->bgColor->getColorIndex(), $this->bgColor->getAlpha())); $new_imgres = imagecreatetruecolor($aResource->getX(), $aResource->getY()); $success = imagecopy($new_imgres, $aResource->getResource(), 0, 0, 0, 0, $aResource->getX(), $aResource->getY()); if (!$success) { throw new FilterException(self::$filterType); } imagedestroy($new_imgres); }
/** * 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; }
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'); }
/** * 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()); }