Browse Source

Ensure that the watermark is always centered when replicated

DarthSim 1 year ago
parent
commit
aeb2c087d4
2 changed files with 15 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 14 2
      vips/vips.c

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@
 
 ### Change
 - Respond with 404 when the bucket/container name or object key is empty in an S3, Google Cloud Storage, Azure Blob Storage, or OpenStack Object Storage (Swift) URL.
+- Ensure that the watermark is always centered when replicated.
 - (pro) Improve unsharp masking.
 - (docker) Update AWS Lambda adapter to 0.8.2.
 - (docker) Increase EXIF size limit to 8MB.

+ 14 - 2
vips/vips.c

@@ -695,10 +695,22 @@ vips_replicate_go(VipsImage *in, VipsImage **out, int width, int height)
 {
   VipsImage *tmp;
 
-  if (vips_replicate(in, &tmp, 1 + width / in->Xsize, 1 + height / in->Ysize, NULL))
+  int across = VIPS_CEIL((double) width / in->Xsize);
+  int down = VIPS_CEIL((double) height / in->Ysize);
+
+  if (across % 2 == 0)
+    across++;
+  if (down % 2 == 0)
+    down++;
+
+  if (vips_replicate(in, &tmp, across, down, NULL))
     return 1;
 
-  if (vips_extract_area(tmp, out, 0, 0, width, height, NULL)) {
+  if (vips_extract_area(tmp, out,
+          (tmp->Xsize - width) / 2,
+          (tmp->Ysize - height) / 2,
+          width, height,
+          NULL)) {
     clear_image(&tmp);
     return 1;
   }