Reputation: 153
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?
Upvotes: 3
Views: 1067
Reputation: 1
I got this to work by adding a constant with the path to the image in the model, and using the draw_over option with variant.
Model.rb
WATERMARK_PATH = "#{Rails.root}/public/images/watermark.png"
View.erb
<div class="carousel-item ">
<%= image_tag image.variant(resize: "400x400", combine_options: { gravity: 'center', draw: 'image Over 0,0 0,0 "' + Unit::WATERMARK_PATH.to_s + '"' })%>
</div>
Upvotes: 0
Reputation: 41
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
Upvotes: 2
Reputation: 889
Add simply the gem 'mini_magick', install and follow their instructions.
ActiveStorage will then have access to the API, which you can find here:
https://www.imagemagick.org/script/mogrify.php
Inside active storage, you can access the API like so:
<%= image_tag image.variant(resize: "500x500", monochrome: true) %>
Greetings
Upvotes: 0