Carrierwave为处理后的图像添加水印

发布于 2025-01-03 19:00:06 字数 577 浏览 3 评论 0原文

我尝试使用从多个资源获得的以下代码向处理后的图像添加水印:

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

唯一的问题是,你猜对了,不起作用。 我在日志/控制台中没有收到任何错误

这是我上传并调用的方法,例如:

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

关于获取一些日志以了解为什么这不起作用的任何想法?我的系统(OSX)上安装了 Rmagick gems 和 Imagemagick,并且调整图像大小确实可以正常工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

束缚m 2025-01-10 19:00:06

我就是这样做的,效果很好:

# 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文