Carrierwave add a watermark to processed images

。_饼干妹妹 提交于 2019-11-30 12:32:26

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/9184768/carrierwave-add-a-watermark-to-processed-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!