Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveStorage variant composite

I need to add watermarks to images, cmd ImageMagick command

convert image.png watermark.png -composite target.jpg 

or

composite -watermark 30% -tile watermark.png image.png target.jpg

How can I do this operation with ActiveStorage::Variant?

like image 669
Vadim Sergeevich Avatar asked Aug 04 '26 05:08

Vadim Sergeevich


1 Answers

Try this:

def medium_img_watermark
    if self.img_first.attached?
      self.img_first.variant(resize: '1200', quality: 75, density: 96,
                             combine_options: {
                              gravity: 'center',
                              draw: 'image Over 0,0 0,0 "public/logo_white.png"'
                            }).processed
    end
  end
like image 61
Kulikov Dmitrii Avatar answered Aug 06 '26 17:08

Kulikov Dmitrii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!