Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carrierwave add a watermark to processed images

Im trying to add a watermark to processed images with below code I got from several resources:

def watermark
  manipulate! do |img|
    logo = Magick::Image.read("#{Rails.root}/assets/images/watermarks/watermark.png").first
    img = img.composite(logo, Magick::SouthEastGravity, Magick::OverCompositeOp)
  end
end

Only problem is, you guess it, does not work. I get no errors in log/console whatsoever

This is my method inside my uploaded and called like:

def function
  version :thumb do
    process :resize_to_fill => [96, 96]
    process :watermark
  end
end

Any thoughts on getting some logs on why this doesn't work? I have the Rmagick gems and Imagemagick installed on my system (OSX) And resizing of images does work correct.

like image 813
Rubytastic Avatar asked Feb 07 '12 22:02

Rubytastic


1 Answers

I just do it this way and it works very fine:

# Process files as they are uploaded:
process :resize_to_fill => [850, 315]
process :convert => 'png'
process :watermark

def watermark
  manipulate! do |img|
    logo = Magick::Image.read("#{Rails.root}/app/assets/images/watermark.png").first
    img = img.composite(logo, Magick::NorthWestGravity, 15, 0, Magick::OverCompositeOp)
  end
end

B.

like image 130
bmac Avatar answered Oct 10 '22 00:10

bmac