Watermark effect processed by Imagick
@param Imagick $image
350312
private function applyWatermarkImagick(Imagick $image)
    {
        $pictureWidth  = $image->getImageWidth();
        $pictureHeight = $image->getImageHeight();

        $watermarkPicture = new Picture($this->watermark, NULL, Picture::WORKER_IMAGICK);

        $opacity = new Opacity($this->opacity);
        $opacity->apply($watermarkPicture);

        if($this->size)
        {
            $resize = new Resize(
                $pictureWidth / 100 * $this->size,
                $pictureHeight / 100 * $this->size,
                Resize::MODE_FIT
            );

            $resize->apply($watermarkPicture);
        }

        $watermark = $watermarkPicture->getResource(Picture::WORKER_IMAGICK);

        $watermarkWidth  = $watermark->getImageWidth();
        $watermarkHeight = $watermark->getImageHeight();

        switch($this->position)
        {
            case 'repeat':

                for($w = 0; $w < $pictureWidth; $w += $watermarkWidth + $this->space)
                {
                    for($h = 0; $h < $pictureHeight; $h += $watermarkHeight + $this->space)
                    {
                        $image->compositeImage($watermark, $watermark->getImageCompose(), $w, $h);
                    }
                }
                return;

            case 'center':

                $positionX = ($image->getImageWidth() - $watermark->getImageWidth()) / 2 - $this->offsetX;
                $positionY = ($image->getImageHeight() - $watermark->getImageHeight()) / 2 - $this->offsetY;
                break;

            case 'topRight':

                $positionX = $image->getImageWidth() - $watermark->getImageWidth() - $this->offsetX;
                $positionY = $this->offsetY;
                break;

            case 'bottomRight':

                $positionX = $image->getImageWidth()  - $watermark->getImageWidth()  - $this->offsetX;
                $positionY = $image->getImageHeight() - $watermark->getImageHeight() - $this->offsetY;
                break;

            case 'bottomLeft':

                $positionX = $this->offsetX;
                $positionY = $image->getImageHeight() - $watermark->getImageHeight() - $this->offsetY;
                break;

            default:

                $positionX = $this->offsetX;
                $positionY = $this->offsetY;
                break;
        }

        $image->compositeImage($watermark, $watermark->getImageCompose(), $positionX, $positionY);
    }
1145976
public function apply(ImageInterface $image)
    {
        /** @var \Imagick $imagick */
        $imagick = $image->getImagick();
        $imagick->reduceNoiseImage((float)$this->getOption('radius', 0));

        return $image;
    }
350452
public function execute($image)
    {
        $base = $this->argument(0)->type('string')->value();
        $away = $this->argument(1)->value();
        $tolerance = $this->argument(2)->type('numeric')->value(0);
        $feather = $this->argument(3)->type('numeric')->value(0);

        $width = $image->getWidth();
        $height = $image->getHeight();

        // default values
        $checkTransparency = false;

        // define borders to trim away
        if (is_null($away)) {
            $away = ['top', 'right', 'bottom', 'left'];
        } elseif (is_string($away)) {
            $away = [$away];
        }

        // lower border names
        foreach ($away as $key => $value) {
            $away[$key] = strtolower($value);
        }

        // define base color position
        switch (strtolower($base)) {
            case 'transparent':
            case 'trans':
                $checkTransparency = true;
                $base_x = 0;
                $base_y = 0;
                break;

            case 'bottom-right':
            case 'right-bottom':
                $base_x = $width - 1;
                $base_y = $height - 1;
                break;

            default:
            case 'top-left':
            case 'left-top':
                $base_x = 0;
                $base_y = 0;
                break;
        }

        // pick base color
        if ($checkTransparency) {
            $color = new Color; // color will only be used to compare alpha channel
        } else {
            $color = $image->pickColor($base_x, $base_y, 'object');
        }

        $top_x = 0;
        $top_y = 0;
        $bottom_x = $width;
        $bottom_y = $height;

        // search upper part of image for colors to trim away
        if (in_array('top', $away)) {

            for ($y=0; $y < ceil($height/2); $y++) {
                for ($x=0; $x < $width; $x++) {

                    $checkColor = $image->pickColor($x, $y, 'object');

                    if ($checkTransparency) {
                        $checkColor->r = $color->r;
                        $checkColor->g = $color->g;
                        $checkColor->b = $color->b;
                    }

                    if ($color->differs($checkColor, $tolerance)) {
                        $top_y = max(0, $y - $feather);
                        break 2;
                    }

                }
            }

        }

        // search left part of image for colors to trim away
        if (in_array('left', $away)) {

            for ($x=0; $x < ceil($width/2); $x++) {
                for ($y=$top_y; $y < $height; $y++) {

                    $checkColor = $image->pickColor($x, $y, 'object');

                    if ($checkTransparency) {
                        $checkColor->r = $color->r;
                        $checkColor->g = $color->g;
                        $checkColor->b = $color->b;
                    }

                    if ($color->differs($checkColor, $tolerance)) {
                        $top_x = max(0, $x - $feather);
                        break 2;
                    }

                }
            }

        }

        // search lower part of image for colors to trim away
        if (in_array('bottom', $away)) {

            for ($y=($height-1); $y >= floor($height/2)-1; $y--) {
                for ($x=$top_x; $x < $width; $x++) {

                    $checkColor = $image->pickColor($x, $y, 'object');

                    if ($checkTransparency) {
                        $checkColor->r = $color->r;
                        $checkColor->g = $color->g;
                        $checkColor->b = $color->b;
                    }

                    if ($color->differs($checkColor, $tolerance)) {
                        $bottom_y = min($height, $y+1 + $feather);
                        break 2;
                    }

                }
            }

        }

        // search right part of image for colors to trim away
        if (in_array('right', $away)) {

            for ($x=($width-1); $x >= floor($width/2)-1; $x--) {
                for ($y=$top_y; $y < $bottom_y; $y++) {

                    $checkColor = $image->pickColor($x, $y, 'object');

                    if ($checkTransparency) {
                        $checkColor->r = $color->r;
                        $checkColor->g = $color->g;
                        $checkColor->b = $color->b;
                    }

                    if ($color->differs($checkColor, $tolerance)) {
                        $bottom_x = min($width, $x+1 + $feather);
                        break 2;
                    }

                }
            }

        }


        // trim parts of image
        return $this->modify($image, 0, 0, $top_x, $top_y, ($bottom_x-$top_x), ($bottom_y-$top_y), ($bottom_x-$top_x), ($bottom_y-$top_y));

    }
714652
public function execute($image)
    {
        $source = $this->argument(0)->required()->value();
        $position = $this->argument(1)->type('string')->value();
        $x = $this->argument(2)->type('digit')->value(0);
        $y = $this->argument(3)->type('digit')->value(0);

        // build watermark
        $watermark = $image->getDriver()->init($source);

        // define insertion point
        $image_size = $image->getSize()->align($position, $x, $y);
        $watermark_size = $watermark->getSize()->align($position);
        $target = $image_size->relativePosition($watermark_size);

        // insert image at position
        imagealphablending($image->getCore(), true);
        return imagecopy($image->getCore(), $watermark->getCore(), $target->x, $target->y, 0, 0, $watermark_size->width, $watermark_size->height);
    }
163232
private function _computeResolution($image)
    {
        $this->res = "MED";
        if(preg_match("/HiRes/i", $image))
            $this->res = "HIGH";
        elseif (preg_match("/LowRes/i", $image))
            $this->res = "LOW";
        elseif (preg_match("/Thumb/i", $image))
            $this->res = "THUMB";
        elseif (preg_match("/MediumRes/i", $image))
            $this->res = "MED";
    }
869916
public function apply(Picture $picture)
    {
        if($picture->isGd() || $picture->gdAvailable())
        {
            $resource = $picture->getResource($picture::WORKER_GD);

            imagefilter($resource, IMG_FILTER_NEGATE);

            $picture->setResource($resource);
        }
        else
        {
            // NEGATIVE IS NOT SUPPORTED IN IMAGICK
        }
    }
796700
protected function resize(Imagick $image, $width, $height)
    {
        $image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1);

        return $image;
    }
206549
public function flatten(&$image){
        if($image->isAnimated()){
            $imagick = $image->getCore()->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
            $image = new Image(
                $imagick,
                $image->getImageFile(),
                $image->getWidth(),
                $image->getHeight(),
                $image->getType(),
                '', // blocks
                false // animated
            );
        }
        return $this;
    }
1217692
public function do_watermark($file, $offsetX = 0, $offsetY = 0, $opacity = 1.0)
    {
        $file = $this->alias->resolve($file);

        list($maskWidth, $maskHeight, $maskType) = getimagesize($file);

        if ($maskType === IMAGETYPE_GIF) {
            $maskImage = imagecreatefromgif($file);
        } elseif ($maskType === IMAGETYPE_JPEG) {
            $maskImage = imagecreatefromjpeg($file);
        } elseif ($maskType === IMAGETYPE_PNG) {
            $maskImage = imagecreatefrompng($file);
        } else {
            throw new PreconditionException('Installed GD does not support such images');
        }

        imagesavealpha($maskImage, true);

        $image = imagecreatetruecolor($this->_width, $this->_height);
        imagealphablending($image, false);
        imagesavealpha($image, true);
        if ($maskType !== IMAGETYPE_PNG) {
            $filedColor = imagecolorallocatealpha($image, 127, 127, 127, (1 - $opacity) * 127);
        } else {
            $filedColor = imagecolorallocate($image, 127, 127, 127);
        }

        imagelayereffect($maskImage, IMG_EFFECT_OVERLAY);
        imagefilledrectangle($maskImage, 0, 0, $maskWidth, $maskHeight, $filedColor);
        imagealphablending($this->_image, true);
        imagecopy($this->_image, $maskImage, $offsetX, $offsetY, 0, 0, $maskWidth, $maskHeight);

        return $this;
    }
981250
protected function applyWatermarkGD($resource, Picture $picture) {

        // SOURCE IMAGE DIMENSIONS
        $pictureWidth  = imagesx($resource);
        $pictureHeight = imagesy($resource);

        // WATERMARK DIMENSIONS
        $watermarkPicture = new Picture($this->watermark, NULL, Picture::WORKER_GD);

        $opacity = new Opacity($this->opacity);
        $opacity->apply($watermarkPicture);

        if($this->size)
        {
            $resize = new Resize(
                $pictureWidth / 100 * $this->size,
                $pictureHeight / 100 * $this->size,
                Resize::MODE_FIT
            );

            $resize->apply($watermarkPicture);
        }

        $watermark = $watermarkPicture->getResource($watermarkPicture::WORKER_GD);

        imagealphablending($watermark, TRUE);

        $watermarkWidth  = imagesx($watermark);
        $watermarkHeight = imagesx($watermark);

        // CALCULATE WATERMARK POSITION
        switch($this->position)
        {
            case 'repeat':

                for($w = 0; $w < $pictureWidth; $w += $watermarkWidth + $this->space)
                {
                    for($h = 0; $h < $pictureHeight; $h += $watermarkHeight + $this->space)
                    {
                        imagecopy($resource, $watermark, $w, $h, 0, 0, $watermarkWidth, $watermarkHeight);
                    }
                }

                return $resource;

            case 'center':

                $positionX = ($pictureWidth - $watermarkWidth) / 2 - $this->offsetX;
                $positionY = ($pictureHeight - $watermarkHeight) / 2 - $this->offsetY;
                break;

            case 'topRight':

                $positionX = $pictureWidth - $watermarkWidth - $this->offsetX;
                $positionY = $this->offsetY;
                break;

            case 'bottomRight':

                $positionX = $pictureWidth  - $watermarkWidth  - $this->offsetX;
                $positionY = $pictureHeight - $watermarkHeight - $this->offsetY;
                break;

            case 'bottomLeft':

                $positionX = $this->offsetX;
                $positionY = $pictureHeight - $watermarkHeight - $this->offsetY;
                break;

            default:

                $positionX = $this->offsetX;
                $positionY = $this->offsetY;
                break;
        }

        imagecopy($resource, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight);

        return $resource;
    }
791403
public function removeImage(Image $image)
    {
        // Find the image based on UUID inside the internal state.
        // Use the image from the internal state.
        $existingImage = $this->images->findImageByUUID($image->getMediaObjectId());

        if ($existingImage) {
            $this->apply(
                $this->createImageRemovedEvent($existingImage)
            );
        }
    }
948185
protected function applyWatermark($im) {
	    
	    // text to watermark with	    
	    if(method_exists($this->media, 'getWatermarkText')) {
	       $word1_text = $this->media->getWatermarkText();
	    }
	    else {
	        $word1_text = $this->media->getTitle();
	    }
	
	    $this->embedText(
	        $im, 
	        $word1_text, 
	        $this->font_max_size,
	        $this->font_color,
	        WT_ROOT . Config::FONT_DEJAVU_SANS_TTF,
	        'top', 
	        'left'
	     );
	
	    return ($im);
	}
129850
public function do_watermark($file, $offsetX = 0, $offsetY = 0, $opacity = 1.0)
    {
        $watermark = new \Imagick($this->alias->resolve($file));

        if ($watermark->getImageAlphaChannel() === \Imagick::ALPHACHANNEL_UNDEFINED) {
            $watermark->setImageOpacity($opacity);
        }

        if ($watermark->getNumberImages() !== 1) {
            throw new PreconditionException(['not support multiple iterations: `:file`', 'file' => $file]);
        }

        if (!$this->_image->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY)) {
            throw new RuntimeException('Imagick::compositeImage Failed');
        }

        $watermark->clear();
        $watermark->destroy();

        return $this;
    }
133524
public function execute($image)
    {
        $transparency = $this->argument(0)->between(0, 100)->required()->value();
        
        $transparency = $transparency > 0 ? (100 / $transparency) : 1000;

        return $image->getCore()->evaluateImage(\Imagick::EVALUATE_DIVIDE, $transparency, \Imagick::CHANNEL_ALPHA);
    }
469823
public function applyToImage(Image $image, $x = 0, $y = 0)
    {
        $rectangle = new \ImagickDraw;

        // set background
        $bgcolor = new Color($this->background);
        $rectangle->setFillColor($bgcolor->getPixel());

        // set border
        if ($this->hasBorder()) {
            $border_color = new Color($this->border_color);
            $rectangle->setStrokeWidth($this->border_width);
            $rectangle->setStrokeColor($border_color->getPixel());
        }

        $rectangle->rectangle($this->x1, $this->y1, $this->x2, $this->y2);

        $image->getCore()->drawImage($rectangle);

        return true;
    }
1175835
public function execute($image)
    {
        $amount = (int) $this->argument(0)->between(0, 100)->value(1);

        for ($i=0; $i < $amount; ++$i) {
            imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR);
        }

        return true;
    }
482694
public function apply( $image ) {

        // normalize colorize levels
        $red = $this->normalizeLevel($this->red);
        $green = $this->normalizeLevel($this->green);
        $blue = $this->normalizeLevel($this->blue);
        $qrange = $image->getCore()->getQuantumRange();

        $image->getCore()->levelImage(0, $red, $qrange['quantumRangeLong'], \Imagick::CHANNEL_RED);
        $image->getCore()->levelImage(0, $green, $qrange['quantumRangeLong'], \Imagick::CHANNEL_GREEN);
        $image->getCore()->levelImage(0, $blue, $qrange['quantumRangeLong'], \Imagick::CHANNEL_BLUE);

        return $image;
    }