浏览代码

Offsets for replicated watermarks

DarthSim 3 年之前
父节点
当前提交
3e87bd683c
共有 3 个文件被更改,包括 11 次插入1 次删除
  1. 1 0
      CHANGELOG.md
  2. 1 1
      docs/generating_the_url.md
  3. 9 0
      processing/watermark.go

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@
 ### Change
 - Improved ICC profiles handling.
 - Proper error message when the deprecated basic URL format is used.
+- Watermark offsets can be applied to replicated watermarks.
 
 ### Fix
 - (pro) Fix parsing metadata of extended sequential JPEGs.

+ 1 - 1
docs/generating_the_url.md

@@ -414,7 +414,7 @@ Puts watermark on the processed image.
   * `soea`: south-east (bottom-right corner);
   * `sowe`: south-west (bottom-left corner);
   * `re`: replicate watermark to fill the whole image;
-* `x_offset`, `y_offset` - (optional) specify watermark offset by X and Y axes. Not applicable to `re` position;
+* `x_offset`, `y_offset` - (optional) specify watermark offset by X and Y axes. For `re` position, define spacing between tiles;
 * `scale` - (optional) floating point number that defines watermark size relative to the resulting image size. When set to `0` or omitted, watermark size won't be changed.
 
 Default: disabled

+ 9 - 0
processing/watermark.go

@@ -16,6 +16,7 @@ var watermarkPipeline = pipeline{
 	importColorProfile,
 	scale,
 	rotateAndFlip,
+	padding,
 	finalize,
 }
 
@@ -35,6 +36,14 @@ func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options
 		po.Height = imath.Max(imath.Scale(imgHeight, opts.Scale), 1)
 	}
 
+	if opts.Replicate {
+		po.Padding.Enabled = true
+		po.Padding.Left = int(opts.Gravity.X / 2)
+		po.Padding.Right = int(opts.Gravity.X) - po.Padding.Left
+		po.Padding.Top = int(opts.Gravity.Y / 2)
+		po.Padding.Bottom = int(opts.Gravity.Y) - po.Padding.Top
+	}
+
 	if err := watermarkPipeline.Run(context.Background(), wm, po, wmData); err != nil {
 		return err
 	}