Application du filtre

@param  resource $imageRessource  ImageRessource GD sur lequel appliquer le filtre
@return resource                  ImageRessource GD modifiée
421064
public function apply($imageRessource)
  {
    $color = imagecolorallocate($imageRessource, $this->r, $this->g, $this->b);
    imagefilledrectangle($imageRessource, $this->x1, $this->y1, $this->x2, $this->y2, $color);
    return $imageRessource;
  }
1324588
public function saveImageResource(ImageResource $imageResource) {
		$resource = $imageResource->getHandle();
		imagesavealpha($resource, true);
		IoUtils::imagePng($resource, $this->getFileName(), 9, PNG_ALL_FILTERS);
	}
246707
public function apply($imageRessource)
  {
    $startWidth = imagesx($imageRessource);
    $startHeight = imagesy($imageRessource);

    // On effectue au préalable un resize
    $xratio = $startWidth / $this->width;
    $yratio = $startHeight / $this->height;
    if ($xratio == $yratio) {
      if ($startHeight == $this->height && $startWidth == $this->width) {
        return $imageRessource;
      }
      $newWidth  = $this->width;
      $newHeight = $this->height;
    } else if($xratio > $yratio) {
      $newHeight = $this->height;
      $newWidth  = $startWidth * $newHeight / $startHeight;
    } else {
      $newWidth  = $this->width;
      $newHeight = $startHeight * $newWidth / $startWidth;
    }

    if (isset($newHeight)) {
      $resizedTmp = Image::createEmptyContainer($newWidth, $newHeight);
      imagecopyresampled($resizedTmp, $imageRessource, 0, 0, 0, 0, $newWidth, $newHeight, $startWidth, $startHeight);
    }
    imagedestroy($imageRessource);

    // On coupe les cotés ou le haut
    $startWidth = imagesx($resizedTmp);
    $startHeight = imagesy($resizedTmp);

    if ($startWidth == $this->width && $startHeight == $this->height) {

      // Cas particulier, aucune opération complémentaire nécessaire
      return $resizedTmp;

    } else if ($startWidth == $this->width) {

      // On a redimensionné sur la largeur. On coupe le haut et le bas
      $resized = Image::createEmptyContainer($this->width, $this->height);
      $xdecay = 0;
      $ydecay = null;

      if($this->verticalPosition == self::VERTICAL_TOP){
        $ydecay = 0;
      } else if ($this->verticalPosition == self::VERTICAL_BOTTOM) {
        $ydecay = $startHeight - $this->height;
      } else if ($this->verticalPosition == self::VERTICAL_CENTER) {
        $ydecay = ($startHeight - $this->height) / 2;
      }

      imagecopyresampled($resized, $resizedTmp, 0, 0, $xdecay, $ydecay, $this->width, $this->height, $this->width, $this->height);
      imagedestroy($resizedTmp);
      return $resized;

    } else {

      // On a redimensionné sur la hauteur. On coupe à droite et à gauche
      $resized = Image::createEmptyContainer($this->width, $this->height);
      $xdecay = null;
      $ydecay = 0;

      if($this->horizontalPosition == self::HORIZONTAL_LEFT){
        $xdecay = 0;
      }else if($this->horizontalPosition == self::HORIZONTAL_RIGHT){
        $xdecay = $startWidth - $this->width;
      }else if($this->horizontalPosition == self::HORIZONTAL_CENTER){
        $xdecay = ($startWidth - $this->width) / 2;
      }

      imagecopyresampled($resized, $resizedTmp, 0, 0, $xdecay, $ydecay, $this->width, $this->height, $this->width, $this->height);
      imagedestroy($resizedTmp);
      return $resized;

    }
  }
985963
public function apply($resource){
		// Extract arguments
		@list(,$rplus,$gplus,$bplus)=func_get_args();
		$rplus=(int)$rplus;
		$gplus=(int)$gplus;
		$bplus=(int)$bplus;
		// Get resolution
		$width=imagesx($resource);
		$height=imagesy($resource);
		if(!$width || !$height){
			throw new Exception("An error was encountered while getting image resolution");
		}
		// Apply effect
		$x=0;
		do{
			$y=0;
			do{
				// Get current pixel color
				list($r,$g,$b,$a)=$this->_getColorAt($resource,$x,$y);
				// Define new color
				$b=$r+$bplus;
				$g=$r+$gplus;
				$r+=$rplus;
				// Format
				if($r<0)		$r=0;
				elseif($r>255)	$r=255;
				if($g<0)		$g=0;
				elseif($g>255)	$g=255;
				if($b<0)		$b=0;
				elseif($b>255)	$b=255;
				// Define pixel
				imagesetpixel($resource,$x,$y,imagecolorallocatealpha($resource,$r,$g,$b,$a));
			}
			while(++$y<$height);
		}
		while(++$x<$width);
		return $resource;
	}
744529
public function apply($resource){
		// Verify support
		if(!function_exists('imagefilter')){
			throw new Exception("It seems your PHP version is not compiled with the bundled version of the GD library");
		}
		// Extract arguments
		@list(,$method)=func_get_args();
		// Apply effect
		switch($method){
			case self::GAUSSIAN:
				if(!imagefilter($resource,IMG_FILTER_GAUSSIAN_BLUR)){
					throw new Exception("GAUSSIAN_BLUR filter failed");
				}
				break;
			case self::SELECTIVE:
			default:
				if(!imagefilter($resource,IMG_FILTER_SELECTIVE_BLUR)){
					throw new Exception("SELECTIVE_BLUR filter failed");
				}
		}
		return $resource;
	}
993809
public function cropTransparentImage($imageResource)
    {
        /** @var int $imageTransparency Transparent color */
        $imageTransparency = imagecolorallocatealpha($imageResource, 255, 255, 255, 127);
        /** @var resource $croppedImage Cropped image resource */
        $croppedImage = imagecreatetruecolor($_POST['crop_width'], $_POST['crop_height']);
        // Fill new image with transparent color
        imagefill($croppedImage, 0, 0, $imageTransparency);
        // Save Alpha chanel
        imagesavealpha($croppedImage, true);
        /** @var resource $rotatedImage Rotated image resource */
        $rotatedImage = imagerotate($imageResource, -($_POST['rotate']), $imageTransparency);
        // Copy rotated image to cropped one
        imagecopy(
            $croppedImage,
            $rotatedImage,
            0,
            0,
            $_POST['crop_x'],
            $_POST['crop_y'],
            $_POST['crop_width'],
            $_POST['crop_height']
        );
        // Delete temp image resource
        imagedestroy($rotatedImage);
        // Return result image
        return $croppedImage;
    }
296055
public function apply(ImageInterface $image)
    {
        if (!$image instanceof Image) {
            throw new InvalidArgumentException("This filter is supported by Image Magick driver only!");
        }
        return $image->applyMask($this->shapeMask)->removeTransparency(new Color('fff'));
    }
423362
protected function &getResampleImageResource()
    {
        if ( ! is_resource($this->resampleImageResource)) {
            $this->resampleImageResource = $this->sourceImageResource;
        }

        return $this->resampleImageResource;
    }
517885
public function apply($resource){
		// Extract arguments
		@list(,$level)=func_get_args();
		$level=abs((int)$level);
		if(!$level){
		    $level=5;
		}
		// Get resolution
		$width=imagesx($resource);
		$height=imagesy($resource);
		if(!$width || !$height){
			throw new Exception("An error was encountered while getting image resolution");
		}
		// Apply effect
		$x=0;
		do{
			$y=0;
			do{
				// Get current pixel color
				list($r,$g,$b,$a)=$this->_getColorAt($resource,$x,$y);
				// Generate noise
				$z=rand(-$level,$level);
				// Define color
				$r+=$z;
				$g+=$z;
				$b+=$z;
				if($r<0)		$r=0;
				elseif($r>255)	$r=255;
				if($g<0)		$g=0;
				elseif($g>255)	$g=255;
				if($b<0)		$b=0;
				elseif($b>255)	$b=255;
				// Define new pixel
				imagesetpixel($resource,$x,$y,imagecolorallocatealpha($resource,$r,$g,$b,$a));
			}
			while(++$y<$height);
		}
		while(++$x<$width);
		return $resource;
	}
994279
public function apply($resource){
		// Get resolution
		$width=imagesx($resource);
		$height=imagesy($resource);
		if($width===false || $height===false){
			throw new Exception("An error was encountered while getting image resolution");
		}
		// Image conversion
		$new=imagecreatetruecolor($width,$height);
		if(!imagecopy($new,$resource,0,0,0,0,$width,$height)){
			throw new Exception("An error was encountered while copying image");
		}
		return $new;
	}
723329
public function imagecolorallocate($imageResource)
	{
		
		return imagecolorallocate(
			$imageResource,
			$this->_r,
			$this->_g,
			$this->_b
		);
		
	}
479560
public function getImage($parameter, $source, $filter = null)
    {
        $this->imageResolver->setParameter($parameter);
        $this->imageResolver->setSource($source);
        $this->imageResolver->setFilter($filter);

        if ($image = $this->imageResolver->resolve()) {
            return $this->render($image);
        }

        return $this->notFound();
    }
253003
public function cropImage($imageResource)
    {
        /** @var int $imageTransparency Transparent color */
        $imageTransparency = imagecolorallocatealpha($imageResource, 255, 255, 255, 127);
        /** @var resource $rotatedImage Rotated image resource */
        $rotatedImage = imagerotate($imageResource, -($_POST['rotate']), $imageTransparency);
        /** @var resource $croppedImage Cropped image resource */
        $croppedImage = imagecrop($rotatedImage, array('x' => $_POST['crop_x'],
            'y' => $_POST['crop_y'],
            'width' => $_POST['crop_width'],
            'height' => $_POST['crop_height']));
        // Delete temp image resource
        imagedestroy($rotatedImage);
        // Return cropped image
        return $croppedImage;
    }
675072
public function getUrlOfFilteredImage($path, $filter, $resolver = null)
    {
        if ($this->cacheManager->isStored($path, $filter, $resolver)) {
            return $this->cacheManager->resolve($path, $filter, $resolver);
        }

        $filteredBinary = $this->createFilteredBinary(
            $path,
            $filter
        );

        $this->cacheManager->store(
            $filteredBinary,
            $path,
            $filter,
            $resolver
        );

        return $this->cacheManager->resolve($path, $filter, $resolver);
    }
733832
private static function _createPng( $imageFile ){
        $gd = @imagecreatefrompng( $imageFile );

        if(!$gd){
            throw new \Exception( sprintf('Could not open "%s". Not a valid %s file.', $imageFile, ImageType::PNG) );
        }

        $image = new self( $gd, $imageFile, imagesx( $gd ), imagesy( $gd ), ImageType::PNG );
        $image->fullAlphaMode( true );
        return $image;
    }
1153172
public function load($url)
    {
        if (file_exists($url)) {
            return $this->validate($url);
        }

        if (preg_match('#^(https?|spdy)://#', $url)) {

            if ($file = $this->loadRemoteFile($url)) {
                return $this->validate($file);
            }
        }

        throw new ImageResourceLoaderException(sprintf('Invalid Source URL: %s', $url));
    }
709315
public function apply($imageRessource)
  {
    $width = imagesx($imageRessource);
    $height = imagesy($imageRessource);
    for ($x = 0; $x < $width; $x++) {
      for ($y = 0; $y < $height; $y++) {
        $color = imagecolorallocatealpha($imageRessource, $this->red, $this->green, $this->blue, $this->opacity);
        imagesetpixel($imageRessource, $x, $y, $color);
      }
    }
    return $imageRessource;
  }