Watermark after resizing (+ thanks)


First, tons of thanks to Janko and those who made this incredibly powerful gem. Just started to use it for one project after using Paperclip for years and recently Active Storage.

I’m a bit stuck about watermarking an image and derivatives.

I’ve several derivates like so :

class ImageUploader < Shrine
  watermark = "#{Rails.root}/public/watermark.png"
  Attacher.derivatives do |original|
    normal = ImageProcessing::MiniMagick.source(original).saver(quality: 76)
    lower  = ImageProcessing::MiniMagick.source(original).composite(watermark, mode: "over", gravity: "south-east", offset: [300, 300]).saver(quality: 72)

      large:        lower.resize_to_limit!(1920,  nil),
      medium:       normal.resize_to_limit!(1200, nil),
      small:        normal.resize_to_limit!(600,  nil),
      pinterest:    normal.resize_to_fill!(1000,  1500),
      placeholder:  normal.blur('0x9').resize_to_limit!(3, nil)

Things are pretty straightforward here. My problem comes when a user upload different sizes of images. The offset (and the size of the watermark) will not be the same, because it merge files before resizing.

Any clue ? Maybe using a different source file that has been already resized before applying composing.