Fix watermarks overlapping animation frames in some cases

This commit is contained in:
DarthSim
2024-04-24 21:42:29 +03:00
parent aeb2c087d4
commit 97217949a7
2 changed files with 33 additions and 1 deletions

View File

@@ -15,6 +15,7 @@
### Fix
- Fix parsing some TIFFs.
- Fix over-shrinking during scale-on-load.
- Fix watermarks overlapping animation frames in some cases.
- (pro) Fix false-positive video detections.
## [3.23.0] - 2024-03-11

View File

@@ -120,9 +120,40 @@ func applyWatermark(img *vips.Image, wmData *imagedata.ImageData, opts *options.
}
left, top := 0, 0
wmWidth := wm.Width()
wmHeight := wm.Height()
if !opts.ShouldReplicate() {
left, top = calcPosition(width, frameHeight, wm.Width(), wm.Height(), &opts.Gravity, offsetScale, true)
left, top = calcPosition(width, frameHeight, wmWidth, wmHeight, &opts.Gravity, offsetScale, true)
}
if left >= width || top >= height || -left >= wmWidth || -top >= wmHeight {
// Watermark is completely outside the image
return nil
}
// if watermark is partially outside the image, it may partially be visible
// on the next frame. We need to crop it vertically.
// We don't care about horizontal overlap, as frames are stacked vertically
if framesCount > 1 {
cropTop := 0
cropHeight := wmHeight
if top < 0 {
cropTop = -top
cropHeight -= cropTop
top = 0
}
if top+cropHeight > frameHeight {
cropHeight = frameHeight - top
}
if cropTop > 0 || cropHeight < wmHeight {
if err := wm.Crop(0, cropTop, wmWidth, cropHeight); err != nil {
return err
}
}
}
for i := 0; i < framesCount; i++ {