( ctx context.Context, wm *vips.Image, wmData imagedata.ImageData, po ProcessingOptions, imgWidth, imgHeight int, offsetScale float64, framesCount int, //nolint:unparam )
| 29 | } |
| 30 | |
| 31 | func (p *Processor) prepareWatermark( |
| 32 | ctx context.Context, |
| 33 | wm *vips.Image, |
| 34 | wmData imagedata.ImageData, |
| 35 | po ProcessingOptions, |
| 36 | imgWidth, imgHeight int, |
| 37 | offsetScale float64, |
| 38 | framesCount int, //nolint:unparam |
| 39 | ) error { |
| 40 | if err := wm.Load(wmData, 1.0, 0, 1); err != nil { |
| 41 | return err |
| 42 | } |
| 43 | |
| 44 | _, _, err := p.checkImageSize(wm, wmData.Format(), po) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | |
| 49 | wmPo := p.NewProcessingOptions(options.New()) |
| 50 | wmPo.Set(keys.ResizingType, ResizeFit) |
| 51 | wmPo.Set(keys.Dpr, 1) |
| 52 | wmPo.Set(keys.Enlarge, true) |
| 53 | wmPo.Set(keys.Format, wmData.Format()) |
| 54 | |
| 55 | if scale := po.WatermarkScale(); scale > 0 { |
| 56 | wmPo.Set(keys.Width, max(imath.ScaleToEven(imgWidth, scale), 1)) |
| 57 | wmPo.Set(keys.Height, max(imath.ScaleToEven(imgHeight, scale), 1)) |
| 58 | } |
| 59 | |
| 60 | shouldReplicate := shouldReplicateWatermark(po.WatermarkPosition()) |
| 61 | |
| 62 | if shouldReplicate { |
| 63 | offsetX := po.WatermarkXOffset() |
| 64 | offsetY := po.WatermarkYOffset() |
| 65 | |
| 66 | var padX, padY int |
| 67 | |
| 68 | if math.Abs(offsetX) >= 1.0 { |
| 69 | padX = imath.RoundToEven(offsetX * offsetScale) |
| 70 | } else { |
| 71 | padX = imath.ScaleToEven(imgWidth, offsetX) |
| 72 | } |
| 73 | |
| 74 | if math.Abs(offsetY) >= 1.0 { |
| 75 | padY = imath.RoundToEven(offsetY * offsetScale) |
| 76 | } else { |
| 77 | padY = imath.ScaleToEven(imgHeight, offsetY) |
| 78 | } |
| 79 | |
| 80 | wmPo.Set(keys.PaddingLeft, padX/2) |
| 81 | wmPo.Set(keys.PaddingRight, padX-padX/2) |
| 82 | wmPo.Set(keys.PaddingTop, padY/2) |
| 83 | wmPo.Set(keys.PaddingBottom, padY-padY/2) |
| 84 | } |
| 85 | |
| 86 | if err := p.watermarkPipeline().Run(ctx, wm, wmPo, wmData); err != nil { |
| 87 | return err |
| 88 | } |
no test coverage detected