{@inheritDoc}
@see \wf\image\ImageInterface::watermark()
979749
public function watermark($watermarkFile = 'static/images/watermark.png', $watermarkPlace = 9, $quality = 95) 
    {
        @list($imgW, $imgH) = $this->imgInfo;
        
        $watermarkInfo    = @getimagesize($watermarkFile);
        $watermarkLogo    = ('image/png' == $watermarkInfo['mime']) ? @imagecreatefrompng($watermarkFile) : @imagecreatefromgif($watermarkFile);

        if(!$watermarkLogo) {
            return;
        }

        list($logoW, $logoH) = $watermarkInfo;
        $wmwidth = $imgW - $logoW;
        $wmheight = $imgH - $logoH;

        if(is_readable($watermarkFile) && $wmwidth > 10 && $wmheight > 10) {
            switch($watermarkPlace) {
                case 1:
                    $x = +5;
                    $y = +5;
                    break;
                case 2:
                    $x = ($imgW - $logoW) / 2;
                    $y = +5;
                    break;
                case 3:
                    $x = $imgW - $logoW - 5;
                    $y = +5;
                    break;
                case 4:
                    $x = +5;
                    $y = ($imgH - $logoH) / 2;
                    break;
                case 5:
                    $x = ($imgW - $logoW) / 2;
                    $y = ($imgH - $logoH) / 2;
                    break;
                case 6:
                    $x = $imgW - $logoW;
                    $y = ($imgH - $logoH) / 2;
                    break;
                case 7:
                    $x = +5;
                    $y = $imgH - $logoH - 5;
                    break;
                case 8:
                    $x = ($imgW - $logoW) / 2;
                    $y = $imgH - $logoH - 5;
                    break;
                case 9:
                    $x = $imgW - $logoW - 5;
                    $y = $imgH - $logoH - 5;
                    break;
            }

            $dstImage = imagecreatetruecolor($imgW, $imgH);
            imagefill($dstImage, 0, 0, imagecolorallocate($dstImage, $this->bgColor[0], $this->bgColor[1], $this->bgColor[2]));            
            $targetImage = @imagecreatefromstring($this->imageContent);
            
            imageCopy($dstImage, $targetImage, 0, 0, 0, 0, $imgW, $imgH);
            imageCopy($dstImage, $watermarkLogo, $x, $y, 0, 0, $logoW, $logoH);

            ob_start();
            imagejpeg($dstImage, null, $quality);
            $ret = ob_get_clean();

            return $ret;
        }
    }
678656
def im_watermark(im, inputtext, font=None, color=None, opacity=.6, margin=(30, 30)):
    """"""
    if im.mode != "RGBA":
        im = im.convert("RGBA")
    textlayer = Image.new("RGBA", im.size, (0, 0, 0, 0))
    textdraw = ImageDraw.Draw(textlayer)
    textsize = textdraw.textsize(inputtext, font=font)
    textpos = [im.size[i] - textsize[i] - margin[i] for i in [0, 1]]
    textdraw.text(textpos, inputtext, font=font, fill=color)
    if opacity != 1:
        textlayer = reduce_opacity(textlayer, opacity)
    return Image.composite(textlayer, im, textlayer)
818368
public function watermarkOpacity(int $opacity)
    {
        if ($opacity < 0 || $opacity > 100) {
            throw InvalidManipulation::valueNotInRange('opacity', $opacity, 0, 100);
        }

        return $this->addManipulation('watermarkOpacity', $opacity);
    }
344198
def watermark(img, mark, position=(0, 0), opacity=1, scale=1.0, tile=False,
              greyscale=False, rotation=0, return_name=False, **kwargs):
    """"""

    if opacity < 1:
        mark = reduce_opacity(mark, opacity)

    if not isinstance(scale, tuple):
        scale = determine_scale(scale, img, mark)

    mark = mark.resize(scale, resample=Image.ANTIALIAS)

    if greyscale and mark.mode != 'LA':
        mark = mark.convert('LA')

    rotation = determine_rotation(rotation, mark)
    if rotation != 0:
        # give some leeway for rotation overlapping
        new_w = int(mark.size[0] * 1.5)
        new_h = int(mark.size[1] * 1.5)

        new_mark = Image.new('RGBA', (new_w, new_h), (0,0,0,0))

        # center the watermark in the newly resized image
        new_l = int((new_w - mark.size[0]) / 2)
        new_t = int((new_h - mark.size[1]) / 2)
        new_mark.paste(mark, (new_l, new_t))

        mark = new_mark.rotate(rotation)

    position = determine_position(position, img, mark)

    if img.mode != 'RGBA':
        img = img.convert('RGBA')

    # make sure we have a tuple for a position now
    assert isinstance(position, tuple), 'Invalid position "%s"!' % position

    # create a transparent layer the size of the image and draw the
    # watermark in that layer.
    layer = Image.new('RGBA', img.size, (0,0,0,0))
    if tile:
        first_y = int(position[1] % mark.size[1] - mark.size[1])
        first_x = int(position[0] % mark.size[0] - mark.size[0])

        for y in range(first_y, img.size[1], mark.size[1]):
            for x in range(first_x, img.size[0], mark.size[0]):
                layer.paste(mark, (x, y))
    else:
        layer.paste(mark, position)

    # composite the watermark with the layer
    return Image.composite(layer, img, layer)
202962
public function openWatermark($watermarkImageFullPath = null)
	{
		if (null !== $watermarkImageFullPath) {
		    $this->setWatermarkFullPath($watermarkImageFullPath);
		}
		$this->thumbnailerService->open($this->getWatermarkFullPath());
		$this->setWatermarkInfo($this->thumbnailerService->getImageInfo());
		
		$watermarkInfo = $this->getWatermarkInfo();
		
        if('image/gif' !== $watermarkInfo['mime']) {
            throw new \RuntimeException("Watermark is required to be of the mimetype image/gif, passed watermark is of mimetype '" . $this->watermarkInfo['mime'] . "'");
        }
		
		return $this;
	}
308854
protected function imageHandle($file)
    {
        if (substr($file, 0, 1) != '/') {
            $file = '/' . $file;
        }


        //先处理缩略图
        if ($this->thumbnail && ! empty($this->thumbnail['height']) && ! empty($this->thumbnail['width'])) {
            $file = pathinfo($file);
            $file = $file['dirname'] . '/' . $file['filename'] . '.thumbnail.' . $file['extension'];
            Image::thumbnail($this->uploadPath . $file, intval($this->thumbnail['width']), intval($this->thumbnail['height']))
                ->save($this->uploadPath . $file);
        }
        //再处理缩放，默认不缩放
        //...缩放效果非常差劲-，-
        if (isset($this->zoom['height']) && isset($this->zoom['width'])) {
            $size = $this->getSize($this->uploadPath . $file);
            if ($size && $size[0] > 0 && $size[1] > 0) {
                $ratio = min([$this->zoom['height'] / $size[0], $this->zoom['width'] / $size[1], 1]);
                Image::thumbnail($this->uploadPath . $file, ceil($size[0] * $ratio), ceil($size[1] * $ratio))
                    ->save($this->uploadPath . $file);
            }
        }
        //最后生成水印
        if (isset($this->watermark['path']) && file_exists($this->watermark['path'])) {
            if (! isset($this->watermark['position']) or $this->watermark['position'] > 9 or $this->watermark['position'] < 0 or ! is_numeric($this->watermark['position'])) {
                $this->watermark['position'] = 9;
            }
            $size = $this->getSize($this->uploadPath . $file);
            $waterSize = $this->getSize($this->watermark['path']);
            if ($size[0] > $waterSize[0] and $size[1] > $waterSize[1]) {
                $halfX = $size[0] / 2;
                $halfY = $size[1] / 2;
                $halfWaterX = $waterSize[0] / 2;
                $halfWaterY = $waterSize[1] / 2;
                switch (intval($this->watermark['position'])) {
                    case 1:
                        $x = 0;
                        $y = 0;
                        break;
                    case 2:
                        $x = $halfX - $halfWaterX;
                        $y = 0;
                        break;
                    case 3:
                        $x = $size[0] - $waterSize[0];
                        $y = 0;
                        break;
                    case 4:
                        $x = 0;
                        $y = $halfY - $halfWaterY;
                        break;
                    case 5:
                        $x = $halfX - $halfWaterX;
                        $y = $halfY - $halfWaterY;
                        break;
                    case 6:
                        $x = $size[0] - $waterSize[0];
                        $y = $halfY - $halfWaterY;
                        break;
                    case 7:
                        $x = 0;
                        $y = $size[1] - $waterSize[1];
                        break;
                    case 8:
                        $x = $halfX - $halfWaterX;
                        $y = $size[1] - $waterSize[1];
                        break;
                    case 9:
                    default:
                        $x = $size[0] - $waterSize[0];
                        $y = $size[1] - $waterSize[1];
                }
                Image::watermark($this->uploadPath . $file, $this->watermark['path'], [$x, $y])
                    ->save($this->uploadPath . $file);
            }
        }

        return $file;
    }
1160431
public function DeleteWaterMark($identifier)
	{
		$sig = $this->encode($this->applicationSecret."|".$identifier);

		$qs = "key=" .urlencode($this->applicationKey)."&identifier=".urlencode($identifier)."&sig=".$sig;

		return $this->isSuccessful($this->Get($this->getRootUrl(false) . "deletewatermark.ashx?" . $qs));
	}
4180
public function markImage( $source, $target = NULL )
	{
		if( !$target )
			$target = $source;
		
		$creator	= new UI_Image_Creator();
		$creator->loadImage( $source );
		$image		= $creator->getResource();
		$type		= $creator->getType();

		$position		= $this->calculatePosition( $creator );
		$stampHeight	= $this->stamp->getHeight();
		$stampWidth		= $this->stamp->getWidth();
		$stampResource	= $this->stamp->getResource();
		imagecopymerge( $image, $stampResource, $position['x'], $position['y'], 0, 0, $stampWidth, $stampHeight, $this->alpha );

		$printer	= new UI_Image_Printer( $image );
		$printer->save( $target, $type );
	}
808070
protected function saveImage()
    {
        if (!$this->image) {
            return parent::path(false);
        }

        $this->filter();

        if (isset($this->result)) {
            return $this->result;
        }

        if (!$this->debug_watermarked && $this->get('debug')) {
            $ratio = $this->get('ratio');
            if (!$ratio) {
                $ratio = 1;
            }

            $locator = Grav::instance()['locator'];
            $overlay = $locator->findResource("system://assets/responsive-overlays/{$ratio}x.png") ?: $locator->findResource('system://assets/responsive-overlays/unknown.png');
            $this->image->merge(ImageFile::open($overlay));
        }

        return $this->image->cacheFile($this->format, $this->quality, false, [$this->get('width'), $this->get('height'), $this->get('modified')]);
    }
11019
private function getWatermark(ImagineInterface $imagine): ?ImageInterface
    {
        $resource = null;
        if ($this->getMarkFilepath() !== null) {
            $resource = fopen($this->getMarkFilepath(), 'rb');
        } elseif (\is_string($this->markContent)) {
            $resource = 'a'; // TODO: create resource.
        } elseif (\is_resource($this->markContent)) {
            $resource = $this->markContent;
        }

        if ($resource === null) {
            return null;
        }

        return $imagine->read($resource);
    }
1286696
public function addImageWatermark(Image $image, array $parameters): Image
    {
        $watermark = new Image($this->secret, $parameters['file'], null, $this->autorotate);

        // temporarily enable alphablending to be able to use 32-bit images
        imagealphablending($watermark->getData(), true);
        imagealphablending($image->getData(), true);

        // determine watermark position from config
        if (true === isset($parameters['position'])) {
            $top = intval($parameters['position']['top']) / 100;
            $left = intval($parameters['position']['left']) / 100;
        } else {
            $top = 1;
            $left = 1;
        }

        // determine watermark size from config
        if (true === isset($parameters['size'])) {
            if (self::WATERMARK_SIZE_COVER === $parameters['size']) {
                // cover dimensions are the same as crop dimensions
                $dimensions = $this->getAdjustedImageCropDimensions(
                    $watermark,
                    $image->getWidth(),
                    $image->getHeight(),
                    true
                );
                imagecopyresampled(
                    $image->getData(),
                    $watermark->getData(),
                    0,
                    0,
                    (int)(($watermark->getWidth() - $dimensions['width']) * $left),
                    (int)(($watermark->getHeight() - $dimensions['height']) * $top),
                    $image->getWidth(),
                    $image->getHeight(),
                    $dimensions['width'],
                    $dimensions['height']
                );
            } elseif (self::WATERMARK_SIZE_CONTAIN === $parameters['size']) {
                $dimensions = $this->getAdjustedImageDimensions($watermark, $image->getWidth(), $image->getHeight());
                imagecopyresampled(
                    $image->getData(),
                    $watermark->getData(),
                    (int)(($image->getWidth() - $dimensions['width']) * $left),
                    (int)(($image->getHeight() - $dimensions['height']) * $top),
                    0,
                    0,
                    $dimensions['width'],
                    $dimensions['height'],
                    $watermark->getWidth(),
                    $watermark->getHeight()
                );
            } else {		// percentage
                $dimensions = $this->getAdjustedImageDimensions($watermark, $image->getWidth(), $image->getHeight());
                $dimensions['width'] *= (intval($parameters['size']) / 100);
                $dimensions['height'] *= (intval($parameters['size']) / 100);
                imagecopyresampled(
                    $image->getData(),
                    $watermark->getData(),
                    (int)(($image->getWidth() - $dimensions['width']) * $left),
                    (int)(($image->getHeight() - $dimensions['height']) * $top),
                    0,
                    0,
                    $dimensions['width'],
                    $dimensions['height'],
                    $watermark->getWidth(),
                    $watermark->getHeight()
                );
            }
        } else {
            imagecopy(
                $image->getData(),
                $watermark->getData(),
                (int)(($image->getWidth() - $watermark->getWidth()) * $left),
                (int)(($image->getHeight() - $watermark->getHeight()) * $top),
                0,
                0,
                $watermark->getWidth(),
                $watermark->getHeight()
            );
        }

        // disable alphablending again to be able to save transparency
        imagealphablending($watermark->getData(), false);
        imagealphablending($image->getData(), false);

        return $image;
    }
1005157
public function image($stream = null){
		if(is_null($stream)){
			$current = current($this->frames);
			return false === $current ? reset($this->frames) : $current;
		} else {
			$this->frames[key($this->frames)] = $stream;
		}
	}
1200159
public static function waterMarkImage($file, $waterFile, $desFile = false, $x = 10, $y = 10, $width = 200, $height = 100)
    {
        try {
            if (is_file($file) && is_file($waterFile)) {
                $ext = pathinfo($file)['extension'];
                $saveFile = $desFile ? $desFile : sys_get_temp_dir() . '/' . uniqid() . '.' . $ext;
                Image::open($file)->merge(Image::open($waterFile), $x, $y, $width, $height)->save($saveFile);

                if (!$desFile && is_file($saveFile)) {
                    $contentType = ContentType::getFileContentType($saveFile);
                    header('Content-type: ' . $contentType);
                    readfile($saveFile);
                }
                return true;
            }
        } catch (Exception $e) {
        }
        return false;
    }
992791
public function setCorePhpthumbNooffsitelinkWatermarkSrc($value)
    {
        $this->setFieldName('phpthumb_nooffsitelink_watermark_src');
        $this->loadObject(true);
        $this->setFieldValue($value);

        return $this;
    }
402692
public function watermark($water, $pos = 0, $tile = false)
    {
        $waterInfo = $this->getImageInfo($water);

        if ( empty($waterInfo['width']) || empty($waterInfo['height']) )
        {
            throw new \InvalidArgumentException('Get watermark file information is failed.');
        }

        $this->waterImage = $this->createFrom($water);

        if (!$this->newImage || !is_resource($this->newImage))
        {
            $this->newImage = $this->sourceImage;
            $sourceWidth    = $this->source['width'];
            $sourceHeight   = $this->source['height'];
        }
        else
        {
            $sourceWidth    = imagesx($this->newImage);
            $sourceHeight   = imagesy($this->newImage);
        }

        $waterWidth  = ($waterInfo['width']  > $sourceWidth)  ? $sourceWidth  : $waterInfo['width'];
        $waterHeight = ($waterInfo['height'] > $sourceHeight) ? $sourceHeight : $waterInfo['height'];

        if ($tile)
        {
            imagealphablending($this->waterImage, true);
            imagesettile($this->newImage, $this->waterImage);
            imagefilledrectangle($this->newImage, 0, 0, $sourceWidth, $sourceHeight, IMG_COLOR_TILED);
        }
        else
        {
            $position = $this->position($pos, $sourceWidth, $sourceHeight, $waterWidth, $waterHeight);

            imagecopy($this->newImage, $this->waterImage, $position['x'], $position['y'], 0, 0, $waterWidth, $waterHeight);
        }

        return $this;
    }
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);
    }
755384
public function watermark(String $source, String $align = NULL, $margin = 0) : Thumb
    {
        $this->sets['watermark'] = [$source, $align, $margin]; 

        return $this;
    }