Search code examples
ruby-on-railscompositeminimagick

How to use carrierwave/minimagick composite to put my logo on the southeast corner of every image uploaded?


I have a model that allows users to upload pictures using carrierwave. I want to put my logo in the southeast corner of each image and then I want the image to save just as it would normally, (example.com/images/1). I know that I have to use composite but despite several hours of googling I am nowhere closer. This was my best guess.

class PictureUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  process resize_to_limit: [400, 400]
  process :logo

def logo
  manipulate! do |img|
    logo = ::MiniMagick::Image.open("#{Rails Name}/app/assets/images/logo.png")
    img = img.composite(logo, Magick::SouthEastGravity, 15, 0, Magick::OverCompositeOp)
  end
end

Solution

  • I believe you can just change this line

    process resize_to_limit: [400, 400]
    

    to this

    process resize_to_limit: [400, 400, 'SouthEast']
    

    And then you may or may not need some of that extra minimagick code you were adding about gravity.