adds a watermark to the image

@param ImageResource $watermark
@param int $watermarkPos
@param int $watermarkMargin
437213
public function watermark(ImageResource $watermark, $watermarkPos = 4, $watermarkMargin = 10) {
		switch($watermarkPos) {
			// center
			case 0:
				$watermarkdestX = $this->width/2 - $watermark->getWidth()/2;
				$watermarkdestY = $this->height/2 - $watermark->getHeight()/2;
				break;
				// top left
			case 1:
				$watermarkdestX = $watermarkMargin;
				$watermarkdestY = $watermarkMargin;
				break;
				// top right
			case 2:
				$watermarkdestX = $this->width - $watermark->getWidth() - $watermarkMargin;
				$watermarkdestY = $watermarkMargin;
				break;
				// bottom left
			case 3:
				$watermarkdestX = $watermarkMargin;
				$watermarkdestY = $this->height - $watermark->getHeight() - $watermarkMargin;
				break;
				// bottom right
			case 4:
			default:
				$watermarkdestX = $this->width - $watermark->getWidth() - $watermarkMargin;
				$watermarkdestY = $this->height - $watermark->getHeight() - $watermarkMargin;
				break;
		}

		// set transparency true
		imagealphablending($this->resource, true);
		$watermarkRes = $watermark->getResource();
		imagealphablending($watermarkRes, true);
		imagecopy($this->resource, $watermarkRes, $watermarkdestX, $watermarkdestY, 0, 0, $watermark->getWidth(), $watermark->getHeight());
	}
1023867
def watermark(self, image, options):
        
        watermark_img = options.get("watermark", settings.THUMBNAIL_WATERMARK)
        if not watermark_img:
            raise AttributeError("No THUMBNAIL_WATERMARK defined or set on tag.")
        watermark_path = find(watermark_img)
        if not watermark_path:
            raise RuntimeError("Could not find the configured watermark file.")
        if not os.path.isfile(watermark_path):
            raise RuntimeError("Set watermark does not point to a file.")

        if "cropbox" not in options:
            options["cropbox"] = None
        if "watermark_alpha" not in options:
            options["watermark_alpha"] = settings.THUMBNAIL_WATERMARK_OPACITY

        mark_sizes = options.get("watermark_size", settings.THUMBNAIL_WATERMARK_SIZE)
        if mark_sizes:
            try:
                options["watermark_size"] = parse_geometry(
                    mark_sizes, self.get_image_ratio(image, options)
                )
            except TypeError as e:
                raise TypeError(
                    "Please, update sorl-thumbnail package version to  >= 11.12b. %s"
                    % e
                )
        else:
            options["watermark_size"] = False

        if "watermark_pos" not in options:
            options["watermark_pos"] = settings.THUMBNAIL_WATERMARK_POSITION

        return self._watermark(
            image,
            watermark_path,
            options["watermark_alpha"],
            options["watermark_size"],
            options["watermark_pos"],
        )
689629
public function assignWatermark(Request $request)
    {
        $getWatermak = $this->getWatermak();

        if(!$getWatermak) {
            return $getWatermak;
        }

        // go through each select image
        foreach ($request->all() as $key => $file){
            $image = new Media($file);

            // check if user has permissions to access this link
            if(!User::hasAccess('Media', 'update', $image->mediaID, true)) {
                return $this->noPermission();
            }

            if ($image->type == "image") {

                // mark original image
                $url = strpos($image->url, '?');
                if($url == false) {
                    $url = base_path($image->url);
                }else{
                    $url = base_path(explode('?', $image->url)[0]);
                }

                // does file exist
                if(!File::exists($url)) {
                    throw new \Exception("Original images ".$url." doesn't exists.");
                }

                $originalImage = Image::make($url);

                // get width of the original image
                $originalWidth = (integer) $originalImage->width();

                // calculate a width for the watermark
                $width = round($originalWidth / 3);

                // get watermark
                $watermark = Image::make($getWatermak->url);

                // resize watermark
                $watermark->resize(
                    $width, null, function ($constraint) {
                        $constraint->aspectRatio();
                    }
                );
                $originalImage->insert($watermark, 'center');
                $originalImage->save($url, 100);

                $image->deleteThumbs();
                $image->createDefaultThumbs();

            }else{
                return "Some files could not be watermaked. Please select only image files.";
            }
        }
        return "OK";
    }
741714
@Override
  public void setActualHighWatermark(WorkUnitState wus) {
    if (Boolean.valueOf(wus.getPropAsBoolean(IS_WATERMARK_WORKUNIT_KEY))) {
      wus.setActualHighWatermark(wus.getWorkunit().getExpectedHighWatermark(MultiKeyValueLongWatermark.class));
    } else {
      wus.setActualHighWatermark(wus.getWorkunit().getExpectedHighWatermark(LongWatermark.class));
    }
  }
765502
public function addImage( $key, $location, $caption = '', $geolocation = '', $title = '', $license = '' )
    {
        /**
         * @var \Lti\Sitemap\SitemapUrl $node
         */
        $node = $this->get( $key );
        if ( ! is_null( $node )) {
            $node->addImage( new SitemapImage( $location, $caption, $geolocation, $title, $license ) );
            $this->hasImages = true;
        }
    }
908507
private void emitRecordWithTimestampAndPunctuatedWatermark(
			T record, KafkaTopicPartitionState<KPH> partitionState, long offset, long kafkaEventTimestamp) {
		@SuppressWarnings("unchecked")
		final KafkaTopicPartitionStateWithPunctuatedWatermarks<T, KPH> withWatermarksState =
				(KafkaTopicPartitionStateWithPunctuatedWatermarks<T, KPH>) partitionState;

		// only one thread ever works on accessing timestamps and watermarks
		// from the punctuated extractor
		final long timestamp = withWatermarksState.getTimestampForRecord(record, kafkaEventTimestamp);
		final Watermark newWatermark = withWatermarksState.checkAndGetNewWatermark(record, timestamp);

		// emit the record with timestamp, using the usual checkpoint lock to guarantee
		// atomicity of record emission and offset state update
		synchronized (checkpointLock) {
			sourceContext.collectWithTimestamp(record, timestamp);
			partitionState.setOffset(offset);
		}

		// if we also have a new per-partition watermark, check if that is also a
		// new cross-partition watermark
		if (newWatermark != null) {
			updateMinPunctuatedWatermark(newWatermark);
		}
	}
293340
public function watermark($mark, $pos, $minSize = false) {
        if ($this->file && is_file($mark)) {
            $image     = new \image ($this->file);
            $iw        = intval($image->imagesx());
            $ih        = intval($image->imagesy());
            $watermark = new \image ($mark);
            $w         = 3 * intval($watermark->imagesx());
            $h         = 3 * intval($watermark->imagesy());
            if ($minSize) {
                $minSize = explode('x', $minSize);
                $w       = intval($minSize [0]);
                if (isset ($minSize [1])) {
                    $h = intval($minSize [1]);
                } else {
                    $h = $w;
                }
            }
            if ($iw > $w && $ih > $h) {
                if ($pos == 'rd') {
                    $pos = array_rand(self::$POSITIONS);
                    $pos = self::$POSITIONS [ $pos ];
                    if ($pos == 'mm') {
                        $pos = 'br';
                    }
                }
                $trans = App::cfg('transxy@media');
                if (!preg_match('/^[1-9]\d*x[1-9]\d*$/', $trans)) {
                    $trans = '0x0';
                }
                $image->attach(new \image_draw_watermark ($watermark, $pos, $trans));
                $rst = $image->save($this->file);
                if (!$rst) {
                    log_error('添加水印失败:' . $this->file);

                    return false;
                }
            }
            $image->destroyImage();
        }

        return true;
    }
1239693
public function watermark(AbstractWatermark $watermark)
    {
        $resampleImageResource =& $this->getResampleImageResource();

        if ($watermark instanceof Text) {

            $draw = new \GmagickDraw();
            $draw->setFont($watermark->getFontPath());
            $draw->setFontSize($watermark->getFontSize());
            $draw->setFillColor($watermark->getFontColor());

            if (false !== ($textAxis = $watermark->getAxis())) {
                $draw->annotation($textAxis->getX(), $textAxis->getY(), $watermark->getString());
            } else {
                switch ($watermark->getPosition()) {
                    default:
                    case 'MIDDLE_MIDDLE':
                    case 'MIDDLE':
                    case 'CENTER':
                        $draw->setgravity(\Gmagick::GRAVITY_CENTER);
                        break;

                    case 'MIDDLE_LEFT':
                        $draw->setgravity(\Gmagick::GRAVITY_WEST);
                        break;

                    case 'MIDDLE_RIGHT':
                        $draw->setgravity(\Gmagick::GRAVITY_EAST);
                        break;

                    case 'MIDDLE_TOP':
                        $draw->setgravity(\Gmagick::GRAVITY_NORTH);
                        break;

                    case 'MIDDLE_BOTTOM':
                        $draw->setgravity(\Gmagick::GRAVITY_SOUTH);
                        break;

                    case 'TOP_LEFT':
                        $draw->setgravity(\Gmagick::GRAVITY_NORTHWEST);
                        break;

                    case 'TOP_RIGHT':
                        $draw->setgravity(\Gmagick::GRAVITY_NORTHEAST);
                        break;

                    case 'BOTTOM_LEFT':
                        $draw->setgravity(\Gmagick::GRAVITY_SOUTHWEST);
                        break;

                    case 'BOTTOM_RIGHT':
                        $draw->setgravity(\Gmagick::GRAVITY_SOUTHEAST);
                        break;
                }
            }

            try {

                $resampleImageResource->annotateimage(
                    $draw,
                    $watermark->getPadding(),
                    $watermark->getPadding(),
                    $watermark->getAngle(),
                    $watermark->getString()
                );

                return true;

            } catch (\GmagickException $e) {

                $this->errors[ $e->getCode() ] = $e->getMessage();

            }
        } elseif ($watermark instanceof Overlay) {
            $watermarkImage = new self;
            $watermarkImage->setSourceImage($watermark->getImagePath());
            $watermarkImage->createFromSource();

            $watermarkImageFile = $watermarkImage->getSourceImageFile();
            $watermarkImageDimension = $watermarkImageFile->getDimension();
            $watermarkImageDimension->maintainAspectRatio = true;

            $resampleImageDimension = $this->resampleImageFile->getDimension();

            if (false === ($scale = $watermark->getImageScale())) {
                $scale = min(
                    round((($resampleImageDimension->getWidth() / 2) / $watermarkImageDimension->getWidth()) * 100),
                    round((($resampleImageDimension->getHeight() / 2) / $watermarkImageDimension->getHeight()) * 100)
                );
            }

            if ($scale > 0) {
                $watermarkImage->setResampleImage($watermarkImageFile->withDimension(
                    $watermarkImageDimension
                        ->withScale($scale)
                ));
            }

            $watermarkImageDimension = $watermarkImage->getResampleImageFile()->getDimension();

            if ($watermarkImage->scale()) {
                $watermarkImageResource = $watermarkImage->getResampleImageResource();

                if (false !== ($watermarkAxis = $watermark->getAxis())) {
                    $watermarkImageAxisX = $watermarkAxis->getX();
                    $watermarkImageAxisY = $watermarkAxis->getY();
                } else {
                    switch ($watermark->getPosition()) {
                        default:
                        case 'MIDDLE_MIDDLE':
                        case 'MIDDLE':
                        case 'CENTER':
                            $watermarkImageAxisX = ($resampleImageDimension->getWidth() - $watermarkImageDimension->getWidth()) / 2;
                            $watermarkImageAxisY = ($resampleImageDimension->getHeight() - $watermarkImageDimension->getHeight()) / 2;
                            break;

                        case 'MIDDLE_LEFT':
                            $watermarkImageAxisX = $watermark->getPadding();
                            $watermarkImageAxisY = ($resampleImageDimension->getHeight() - $watermarkImageDimension->getHeight()) / 2;
                            break;

                        case 'MIDDLE_RIGHT':
                            $watermarkImageAxisX = $resampleImageDimension->getWidth() - ($watermarkImageDimension->getWidth() + $watermark->getPadding());
                            $watermarkImageAxisY = ($resampleImageDimension->getHeight() - $watermarkImageDimension->getHeight()) / 2;
                            break;

                        case 'MIDDLE_TOP':
                            $watermarkImageAxisX = ($resampleImageDimension->getWidth() - $watermarkImageDimension->getWidth()) / 2;
                            $watermarkImageAxisY = $watermarkImageDimension->getHeight() + $watermark->getPadding();
                            break;

                        case 'MIDDLE_BOTTOM':
                            $watermarkImageAxisX = ($resampleImageDimension->getWidth() - $watermarkImageDimension->getWidth()) / 2;
                            $watermarkImageAxisY = $resampleImageDimension->getHeight() - ($watermarkImageDimension->getHeight() + $watermark->getPadding());
                            break;

                        case 'TOP_LEFT':
                            $watermarkImageAxisX = $watermark->getPadding();
                            $watermarkImageAxisY = $watermarkImageDimension->getHeight() + $watermark->getPadding();
                            break;

                        case 'TOP_RIGHT':
                            $watermarkImageAxisX = $resampleImageDimension->getWidth() - ($watermarkImageDimension->getWidth() + $watermark->getPadding());
                            $watermarkImageAxisY = $watermarkImageDimension->getHeight() + $watermark->getPadding();
                            break;

                        case 'BOTTOM_LEFT':
                            $watermarkImageAxisX = $watermark->getPadding();
                            $watermarkImageAxisY = $resampleImageDimension->getHeight() - $watermarkImageDimension->getHeight() + $watermark->getPadding();
                            break;

                        case 'BOTTOM_RIGHT':
                            $watermarkImageAxisX = $resampleImageDimension->getWidth() - ($watermarkImageDimension->getWidth() + $watermark->getPadding());
                            $watermarkImageAxisY = $resampleImageDimension->getHeight() - ($watermarkImageDimension->getHeight() + $watermark->getPadding());
                            break;
                    }
                }

                try {
                    $resampleImageResource->compositeimage($watermarkImageResource, \Gmagick::COMPOSITE_OVER,
                        $watermarkImageAxisX,
                        $watermarkImageAxisY);

                    return true;
                } catch (\GmagickException $e) {
                    $this->errors[ $e->getCode() ] = $e->getMessage();
                }
            }
        }

        return false;
    }
1312017
private static long adjustWatermark(String baseWatermark, WatermarkType watermarkType) {
    long result = ConfigurationKeys.DEFAULT_WATERMARK_VALUE;
    switch (watermarkType) {
      case SIMPLE:
        result = SimpleWatermark.adjustWatermark(baseWatermark, 0);
        break;
      case DATE:
        result = DateWatermark.adjustWatermark(baseWatermark, 0);
        break;
      case HOUR:
        result = HourWatermark.adjustWatermark(baseWatermark, 0);
        break;
      case TIMESTAMP:
        result = TimestampWatermark.adjustWatermark(baseWatermark, 0);
        break;
    }
    return result;
  }
364239
protected function alignImageWatermark($source)
    {
        if( is_string($this->target ?? NULL) )
        {
            $size = getimagesize($source);

            $this->width  = $this->width  ?? $size[0];
            $this->height = $this->height ?? $size[1];

            $return = WatermarkImageAligner::align($this->target, $this->width, $this->height, $this->imageSize[0], $this->imageSize[1], $this->margin ?? 0);

            $this->target = $return;
            
            if( isset($this->x) ) $this->source[0] = $this->x;
            if( isset($this->y) ) $this->source[1] = $this->y;
        }
    }
871093
public function watermark(AbstractWatermark $watermark)
    {
        $resampleImageResource =& $this->getResampleImageResource();

        if ($watermark instanceof Text) {
            $textBox = imagettfbbox($watermark->getFontSize(), $watermark->getAngle(), $watermark->getFontPath(),
                $watermark->getString());

            if ($textBox[ 0 ] < 0 and $textBox[ 6 ]) {
                $textBox[ 1 ] += $textBox[ 0 ];
                $textBox[ 3 ] += $textBox[ 0 ];
                $textBox[ 5 ] += $textBox[ 0 ];
                $textBox[ 7 ] += $textBox[ 0 ];
            }

            $textBox = array_map('abs', $textBox);

            $watermarkImageWidth = max($textBox[ 0 ], $textBox[ 2 ], $textBox[ 4 ], $textBox[ 6 ]);
            $watermarkImageHeight = max($textBox[ 1 ], $textBox[ 3 ], $textBox[ 5 ], $textBox[ 7 ]);

            if (false !== ($watermarkAxis = $watermark->getAxis())) {
                $watermarkImageAxisX = $watermarkAxis->getX();
                $watermarkImageAxisY = $watermarkAxis->getY();
            } else {
                switch ($watermark->getPosition()) {
                    default:
                    case 'MIDDLE_MIDDLE':
                    case 'MIDDLE':
                    case 'CENTER':
                        $watermarkImageAxisX = (imagesx($resampleImageResource) - $watermarkImageWidth) / 2;
                        $watermarkImageAxisY = (imagesy($resampleImageResource) - $watermarkImageHeight) / 2;
                        break;

                    case 'MIDDLE_LEFT':
                        $watermarkImageAxisX = $watermark->getPadding();
                        $watermarkImageAxisY = (imagesy($resampleImageResource) - $watermarkImageHeight) / 2;
                        break;

                    case 'MIDDLE_RIGHT':
                        $watermarkImageAxisX = imagesx($resampleImageResource) - ($watermarkImageWidth + $watermark->getPadding());
                        $watermarkImageAxisY = (imagesy($resampleImageResource) - $watermarkImageHeight) / 2;
                        break;

                    case 'MIDDLE_TOP':
                        $watermarkImageAxisX = (imagesx($resampleImageResource) - $watermarkImageWidth) / 2;
                        $watermarkImageAxisY = $watermarkImageHeight + $watermark->getPadding();
                        break;

                    case 'MIDDLE_BOTTOM':
                        $watermarkImageAxisX = (imagesx($resampleImageResource) - $watermarkImageWidth) / 2;
                        $watermarkImageAxisY = imagesy($resampleImageResource) - ($watermarkImageHeight + $watermark->getPadding());
                        break;

                    case 'TOP_LEFT':
                        $watermarkImageAxisX = $watermark->getPadding();
                        $watermarkImageAxisY = $watermarkImageHeight + $watermark->getPadding();
                        break;

                    case 'TOP_RIGHT':
                        $watermarkImageAxisX = imagesx($resampleImageResource) - ($watermarkImageWidth + $watermark->getPadding());
                        $watermarkImageAxisY = $watermarkImageHeight + $watermark->getPadding();
                        break;

                    case 'BOTTOM_LEFT':
                        $watermarkImageAxisX = $watermark->getPadding();
                        $watermarkImageAxisY = imagesy($resampleImageResource) - $watermarkImageHeight + $watermark->getPadding();
                        break;

                    case 'BOTTOM_RIGHT':
                        $watermarkImageAxisX = imagesx($resampleImageResource) - ($watermarkImageWidth + $watermark->getPadding());
                        $watermarkImageAxisY = imagesy($resampleImageResource) - ($watermarkImageHeight + $watermark->getPadding());
                        break;
                }
            }

            /* Set RGB values for text
             *
             * First character is #, so we don't really need it.
             * Get the rest of the string and split it into 2-length
             * hex values:
             */
            $textColor = str_split(substr($watermark->getFontColor(), 1, 6), 2);
            $textColor = imagecolorclosest($resampleImageResource, hexdec($textColor[ 0 ]),
                hexdec($textColor[ 1 ]),
                hexdec($textColor[ 2 ]));

            imagettftext(
                $resampleImageResource,
                $watermark->getFontSize(),
                $watermark->getAngle(),
                $watermarkImageAxisX,
                $watermarkImageAxisY,
                $textColor,
                $watermark->getFontPath(),
                $watermark->getString()
            );

            return true;
        } elseif ($watermark instanceof Overlay) {

            $watermarkImage = new self;
            $watermarkImage->setSourceImage($watermark->getImagePath());
            $watermarkImage->createFromSource();

            $watermarkImageFile = $watermarkImage->getSourceImageFile();
            $watermarkImageDimension = $watermarkImageFile->getDimension();
            $watermarkImageDimension->maintainAspectRatio = true;

            if (false === ($scale = $watermark->getImageScale())) {
                $scale = min(
                    round(((imagesx($resampleImageResource) / 2) / $watermarkImageDimension->getWidth()) * 100),
                    round(((imagesy($resampleImageResource) / 2) / $watermarkImageDimension->getHeight()) * 100)
                );
            }

            if ($scale > 0) {
                $watermarkImage->setResampleImage($watermarkImageFile->withDimension(
                    $watermarkImageDimension
                        ->withScale($scale)
                ));
            }

            if ($watermarkImage->scale()) {
                $watermarkImageResource = $watermarkImage->getResampleImageResource();

                $watermarkImageWidth = imagesx($watermarkImageResource);
                $watermarkImageHeight = imagesy($watermarkImageResource);

                if (false !== ($watermarkAxis = $watermark->getAxis())) {
                    $watermarkImageAxisX = $watermarkAxis->getX();
                    $watermarkImageAxisY = $watermarkAxis->getY();
                } else {
                    switch ($watermark->getPosition()) {
                        default:
                        case 'MIDDLE_MIDDLE':
                        case 'MIDDLE':
                        case 'CENTER':
                            $watermarkImageAxisX = (imagesx($resampleImageResource) - $watermarkImageWidth) / 2;
                            $watermarkImageAxisY = (imagesy($resampleImageResource) - $watermarkImageHeight) / 2;
                            break;

                        case 'MIDDLE_LEFT':
                            $watermarkImageAxisX = $watermark->getPadding();
                            $watermarkImageAxisY = (imagesy($resampleImageResource) - $watermarkImageHeight) / 2;
                            break;

                        case 'MIDDLE_RIGHT':
                            $watermarkImageAxisX = imagesx($resampleImageResource) - ($watermarkImageWidth + $watermark->getPadding());
                            $watermarkImageAxisY = (imagesy($resampleImageResource) - $watermarkImageHeight) / 2;
                            break;

                        case 'MIDDLE_TOP':
                            $watermarkImageAxisX = (imagesx($resampleImageResource) - $watermarkImageWidth) / 2;
                            $watermarkImageAxisY = $watermarkImageHeight + $watermark->getPadding();
                            break;

                        case 'MIDDLE_BOTTOM':
                            $watermarkImageAxisX = (imagesx($resampleImageResource) - $watermarkImageWidth) / 2;
                            $watermarkImageAxisY = imagesy($resampleImageResource) - ($watermarkImageHeight + $watermark->getPadding());
                            break;

                        case 'TOP_LEFT':
                            $watermarkImageAxisX = $watermark->getPadding();
                            $watermarkImageAxisY = $watermarkImageHeight + $watermark->getPadding();
                            break;

                        case 'TOP_RIGHT':
                            $watermarkImageAxisX = imagesx($resampleImageResource) - ($watermarkImageWidth + $watermark->getPadding());
                            $watermarkImageAxisY = $watermarkImageHeight + $watermark->getPadding();
                            break;

                        case 'BOTTOM_LEFT':
                            $watermarkImageAxisX = $watermark->getPadding();
                            $watermarkImageAxisY = imagesy($resampleImageResource) - $watermarkImageHeight + $watermark->getPadding();
                            break;

                        case 'BOTTOM_RIGHT':
                            $watermarkImageAxisX = imagesx($resampleImageResource) - ($watermarkImageWidth + $watermark->getPadding());
                            $watermarkImageAxisY = imagesy($resampleImageResource) - ($watermarkImageHeight + $watermark->getPadding());
                            break;
                    }
                }

                return imagecopy(
                    $resampleImageResource,
                    $watermarkImageResource,
                    $watermarkImageAxisX,
                    $watermarkImageAxisY,
                    0,
                    0,
                    imagesx($watermarkImageResource),
                    imagesy($watermarkImageResource)
                );
            }
        }

        return false;
    }
303829
def create_watermark(self, target, mark, fpath, quality=QUALITY, **kwargs):
        """"""

        im = utils.watermark(target, mark, **kwargs)
        im.save(fpath, quality=quality)
        return im
992791
public function setCorePhpthumbNooffsitelinkWatermarkSrc($value)
    {
        $this->setFieldName('phpthumb_nooffsitelink_watermark_src');
        $this->loadObject(true);
        $this->setFieldValue($value);

        return $this;
    }
295697
public function addDKIM(string $privateKey, string $domain, string $selector): void
    {
        $signer = new DKIMSigner();
        $signer->privateKey = $privateKey;
        $signer->domain = $domain;
        $signer->selector = $selector;
        $this->set($signer);
    }
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;
    }
217454
protected function do_watermark(\stdClass $src, $watermarkFile) {
		
		if(!file_exists($watermarkFile)) {
			throw new ImageModifierException("Watermark '$watermarkFile' doesn't exist.");
		}
		
		$watermark = new \Imagick($watermarkFile);
		$src->resource->compositeImage($watermark, \Imagick::COMPOSITE_OVER, ($src->width - $watermark->getImageWidth()) / 2, ($src->height - $watermark->getImageHeight()) / 2);
		$src->resource->flattenImages();

		$watermark->clear();

		return $src;
	}
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)