加水印图片
@param string|Image $image
@param int $x
@param int $y
@param int $opacity 透明度，对png图片不起作用
@return bool
173489
public function addImage($image, $x = 0, $y = 0, $opacity = 50) {
		if (!$image instanceof Image) {
			$image = new Image($image);
		}
		if ($image->getRealType() == 'png') {
			return $this->copyFrom($image, 0, 0, $x, $y);
		}
		return $this->copyAndMergeFrom($image, $x, $y, $opacity);
	}
79878
private function createImage($x, $y, $width, $height, $new_width, $new_height, $interlace = false) {

		$resource = imagecreatetruecolor($new_width, $new_height);

		if(false === imagesavealpha($resource, true)) {
			trigger_error('Could not set the flag to save full alpha channel', E_USER_ERROR);
		}

		if(false === imagealphablending($resource, false)) {
			trigger_error('Could not set the blending mode', E_USER_ERROR);
		}

		if(false === imagefill($resource, 0, 0, imagecolorallocate($resource, 255, 255, 255))) {
			trigger_error('Could not flood fill the image', E_USER_ERROR);
		}

		if(false === imagecopyresampled($resource, $this -> image, 0, 0, $x, $y, $new_width, $new_height, $width, $height)) {
			trigger_error('Could not copy and resize part of an image with resampling', E_USER_ERROR);
		}

		if((true === $interlace && imageinterlace($this -> image, true)) || false === $interlace) {
				
			$this -> image = $resource;
			return $this -> image;
		}

		return false;
	}
351755
private function storeImage(Image $image)
    {
        $file = $this->getFile($image);

        if (!$file instanceof \SplFileInfo) {
            return null;
        }

        $path = $this->imageManagerInterface->store($file);

        return $image->setPath($path);
    }
859264
public function applyToImage(Image $image, $x = 0, $y = 0)
    {
        $color = new Color($this->color);
        imageline($image->getCore(), $x, $y, $this->x, $this->y, $color->getInt());

        return true;
    }
437466
public function applyToImage(Image $image, $x = 0, $y = 0)
    {
        // parse background color
        $background = new Color($this->background);

        if ($this->hasBorder()) {
            // slightly smaller ellipse to keep 1px bordered edges clean
            imagefilledellipse($image->getCore(), $x, $y, $this->width-1, $this->height-1, $background->getInt());

            $border_color = new Color($this->border_color);
            imagesetthickness($image->getCore(), $this->border_width);

            // gd's imageellipse doesn't respect imagesetthickness so i use imagearc with 359.9 degrees here
            imagearc($image->getCore(), $x, $y, $this->width, $this->height, 0, 359.99, $border_color->getInt());
        } else {
            imagefilledellipse($image->getCore(), $x, $y, $this->width, $this->height, $background->getInt());
        }

        return true;
    }
1174556
protected function gdImageBackground($image, $bgcolor){

		if( $bgcolor == 'transparent' ){
			imagesavealpha($image,true);
			$bgcolor1 = imagecolorallocatealpha($image, 255, 255, 255, 127);

		}else{
			list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
			$bgcolor1 = imagecolorallocate($image, $r, $g, $b);
		}

		imagefill($image, 0, 0, $bgcolor1);
	}
936483
private function filterOpacity(&$img, $opacity = 75)
		#
		# Author:     aiden dot mail at freemail dot hu
		# Author date:  29-03-08 08:16
		# Date added:   08-05-11
		# Purpose:    Change opacity of image
		# Params in:    $img: Image resource id
		#         (int) $opacity: the opacity amount: 0-100, 100 being not opaque.
		# Params out:   (bool) true on success, else false
		# Ref:      http://www.php.net/manual/en/function.imagefilter.php#82162
		# Notes:      png only
		#
	{

		if ( ! isset($opacity))
		{
			return false;
		}

		if ($opacity == 100)
		{
			return true;
		}

		$opacity /= 100;

		//get image width and height
		$w = imagesx($img);
		$h = imagesy($img);

		//turn alpha blending off
		imagealphablending($img, false);

		//find the most opaque pixel in the image (the one with the smallest alpha value)
		$minalpha = 127;
		for ($x = 0; $x < $w; $x++)
		{
			for ($y = 0; $y < $h; $y++)
			{
				$alpha = (imagecolorat($img, $x, $y) >> 24) & 0xFF;
				if ($alpha < $minalpha)
				{
					$minalpha = $alpha;
				}
			}
		}

		//loop through image pixels and modify alpha for each
		for ($x = 0; $x < $w; $x++)
		{
			for ($y = 0; $y < $h; $y++)
			{
				//get current alpha value (represents the TANSPARENCY!)
				$colorxy = imagecolorat($img, $x, $y);
				$alpha = ($colorxy >> 24) & 0xFF;
				//calculate new alpha
				if ($minalpha !== 127)
				{
					$alpha = 127 + 127 * $opacity * ($alpha - 127) / (127 - $minalpha);
				}
				else
				{
					$alpha += 127 * $opacity;
				}
				//get the color index with new alpha
				$alphacolorxy = imagecolorallocatealpha($img, ($colorxy >> 16) & 0xFF, ($colorxy >> 8) & 0xFF, $colorxy & 0xFF, $alpha);
				//set pixel with the new color + opacity
				if ( ! imagesetpixel($img, $x, $y, $alphacolorxy))
				{

					return false;
				}
			}
		}

		return true;
	}
146925
public function addImage(Image $image)
    {
        // Find the image based on UUID inside the internal state.
        $existingImage = $this->images->findImageByUUID($image->getMediaObjectId());

        if ($existingImage === null) {
            $this->apply(
                $this->createImageAddedEvent($image)
            );
        }
    }
602335
public function addImage($image)
    {
        if (is_array($image)) {
            $this->images = array_merge($this->images, $image);
        } elseif (is_string($image)) {
            $this->images[] = $image;
        }

        return $this;
    }
192822
public function run(Image $image)
    {
        if ($watermark = $this->getImage($image)) {
            $markw = $this->getDimension($image, 'markw');
            $markh = $this->getDimension($image, 'markh');
            $markx = $this->getDimension($image, 'markx');
            $marky = $this->getDimension($image, 'marky');
            $markpad = $this->getDimension($image, 'markpad');
            $markfit = $this->getFit();
            $markpos = $this->getPosition();
            $markalpha = $this->getAlpha();

            if ($markpad) {
                $markx = $marky = $markpad;
            }

            $size = new Size();
            $size->setParams([
                'w' => $markw,
                'h' => $markh,
                'fit' => $markfit,
            ]);
            $watermark = $size->run($watermark);

            if ($markalpha < 100) {
                $watermark->opacity($markalpha);
            }

            $image->insert($watermark, $markpos, intval($markx), intval($marky));
        }

        return $image;
    }
611403
protected function gdLine($image, $num = 4)
    {
        for ($i = 0; $i <= $num; $i++) {
            $randcolor = $this->randColor();
            $color     = imagecolorallocate($image, hexdec(substr($randcolor, 1, 2)), hexdec(substr($randcolor, 3, 2)), hexdec(substr($randcolor, 5, 2)));
            //设置颜色
            $x1 = rand(0, $this->width);
            $y1 = rand(0, $this->height);
            $x2 = rand(0, $this->width);
            $y2 = rand(0, $this->height);
            imageline($image, $x1, $y1, $x2, $y2, $color);
        }
    }
1246061
public function addRectangle($x1, $y1, $x2, $y2, $colors = [0, 0, 0])
    {
        $color = imagecolorallocate($this->image(), $colors[0],  $colors[1],  $colors[2]);
        imagerectangle ( $this->image() , $x1 , $y1 , $x2 , $y2 ,  $color );
    }
580338
public function execute($image)
    {
        $diameter = $this->argument(0)->type('numeric')->required()->value();
        $x = $this->argument(1)->type('numeric')->required()->value();
        $y = $this->argument(2)->type('numeric')->required()->value();
        $callback = $this->argument(3)->type('closure')->value();

        $circle_classname = sprintf('\Intervention\Image\%s\Shapes\CircleShape',
            $image->getDriver()->getDriverName());

        $circle = new $circle_classname($diameter);

        if ($callback instanceof Closure) {
            $callback($circle);
        }

        $circle->applyToImage($image, $x, $y);

        return true;
    }
900957
public function applyToImage(Image $image, $x = 0, $y = 0)
    {
        $circle = new \ImagickDraw;

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

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

        $circle->ellipse($x, $y, $this->width / 2, $this->height / 2, 0, 360);

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

        return true;
    }
509202
public function execute($image)
    {
        $diameter = $this->argument(0)->type('numeric')->required()->value();
        $x = $this->argument(1)->type('numeric')->required()->value();
        $y = $this->argument(2)->type('numeric')->required()->value();
        $callback = $this->argument(3)->type('closure')->value();

        $namespace = $image->getDriver()->getNamespace();
        $circleClassname = "\{$namespace}\Shapes\CircleShape";

        $circle = new $circleClassname($diameter);

        if ($callback instanceof Closure) {
            $callback($circle);
        }

        $circle->applyToImage($image, $x, $y);

        return true;
    }
542131
public function execute($image)
    {
        $mode = $this->argument(0)->type('bool')->value(true);

        if ($mode) {
            $mode = \Imagick::INTERLACE_LINE;
        } else {
            $mode = \Imagick::INTERLACE_NO;
        }

        $image->getCore()->setInterlaceScheme($mode);

        return true;
    }
226297
private function GetPixelColor(&$img, $x, $y)
		# Author:     James Heinrich
		# Purpose:
		# Param in:
		# Param out:
		# Reference:
		# Notes:
		#
	{
		if ( ! is_resource($img))
		{
			return false;
		}

		return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
	}