/** * Applies pixelation effect to the image. * This is a fix for not working IMG_FILTER_PIXELATE and implements mode GD_PIXELATE_UPPERLEFT only. * @access public * @param integer $sizeX Block width in pixels * @param integer $sizeY Block height in pixels * @return void */ public function pixelate2($sizeX = 20, $sizeY = 20) { if (!is_int($sizeX) || $sizeX < 1) { throw new \InvalidArgumentException('SizeX must be integer and atleast 1'); } if (!is_int($sizeY) || $sizeY < 1) { throw new \InvalidArgumentException('SizeY must be integer and atleast 1'); } if ($sizeX == 1 && $sizeY == 1) { throw new \InvalidArgumentException('One of the pixel sizes must differ from 1ss'); } $width = $this->image->getWidth(); $height = $this->image->getHeight(); $image = $this->image->getResource(); for ($y = 0; $y < $height; $y += $sizeY) { for ($x = 0; $x < $width; $x += $sizeX) { $rgb = imagecolorsforindex($image, imagecolorat($image, $x, $y)); // get the color for current pixel $color = imagecolorclosest($image, $rgb['red'], $rgb['green'], $rgb['blue']); // get the closest color from palette imagefilledrectangle($image, $x, $y, $x + $sizeX - 1, $y + $sizeY - 1, $color); // fill block } } }
/** * Scale image to fit into a size range. * Reduces to maximum size after possibly enlarging to minimum size. * Range maximum has higher priority. * For better resolution this method will first maximize and than minimize if both is needed. * @access public * @param integer $minWidth Minimum width * @param integer $minHeight Minimum height * @param integer $maxWidth Maximum width * @param integer $maxHeight Maximum height * @param boolean $interpolate Flag: use interpolation * @param integer $maxMegaPixel Maxiumum megapixels * @return object Processor object for chaining */ public function scaleToRange($minWidth, $minHeight, $maxWidth, $maxHeight, $interpolate, $maxMegaPixel = 50) { $width = $this->image->getWidth(); $height = $this->image->getHeight(); if ($width < $minWidth || $height < $minHeight) { return $this->scaleUpToLimit($minWidth, $minHeight, $interpolate, $maxMegaPixel); } else { if ($width > $maxWidth || $height > $maxHeight) { return $this->scaleDownToLimit($maxWidth, $maxHeight, $interpolate, $maxMegaPixel); } } return $this; }