From aeb2c087d4958a5cccf711ad952eb808240462bd Mon Sep 17 00:00:00 2001 From: DarthSim Date: Wed, 24 Apr 2024 21:18:55 +0300 Subject: [PATCH] Ensure that the watermark is always centered when replicated --- CHANGELOG.md | 1 + vips/vips.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e2fffdd..09d3b9c7 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/vips/vips.c b/vips/vips.c index 0a0a2e78..dcd5d991 100644 --- a/vips/vips.c +++ b/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; }