载波为处理后的图像添加水印 [英] 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
是否有任何关于为什么不起作用的日志的想法?我在系统(OSX)上安装了Rmagick gems和Imagemagick,并且调整图像大小确实可以正常工作。
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.
推荐答案
我只是这样做
# 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
这篇关于载波为处理后的图像添加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文