如何使用活动存储导轨7对pdf文件进行水印或盖章.有可能吗



我想在应用程序的.erb视图文件上向最终用户显示带水印的PDF文件。为了测试的目的,我首先尝试用jpeg图像进行测试我的资源是;

  1. 图像处理宝石
  2. ActiveStorage
  3. Vips宝石

此代码有效,但尚未加水印。

<%= image_tag @image.variant(resize_to_limit: [800, 800], colourspace: "b-w").processed if @image.variable? %> 

此代码不起作用。错误为VipsForeignLoad: file "http://localhost:3000/assets/placeholder-d1fde905b3fe89204148520108a99695bec9458f400d001b08626860983d5377.png" does not exist

<%= image_tag @image.variant(resize_to_limit: [800, 800], colourspace: "b-w",  composite: [asset_url("placeholder.png"), "south-east"] ).processed if @image.variable? %>

我还尝试了另一种方法,但也不起作用。错误为overlay must be a Vips::Image, String, Pathname, or respond to #path

<% water = ImageProcessing::Vips.Image.new %>
<% water.text("TEST KEYWORD")%> 

<%= image_tag @image.variant(resize_to_limit: [800, 800], colourspace: "b-w",  composite: [water, "south-east"] ).processed if @image.variable? %>

这也不起作用。错误类似于no _dump_data is defined for class FFI::Pointer

<%= image_tag @image.variant(resize_to_limit: [800, 800], colourspace: "b-w",  composite: [overlay: Vips::Image.text("asdfasdf")] ).processed if @image.variable? %>

我能够让它使用以下代码。

在控制器中:

@watermark_image = Pathname.new(Rails.root.join('app', 'assets', 'images', 'watermark250x400.png'))

然后在视图中:

<%= image_tag image.variant(resize_to_fit: [500, 500],
composite: [@watermark_image, :over, {x: 0, y: 0, premultiplied: true}]).processed,
class: "some-class", loading: "lazy", alt: "" %>

我想早些时候,我试图通过读取文件来加载图像,而不仅仅是提供路径名(比如water = ImageProcessing::Vips.Image.new(full_path),当时我遇到了同样的错误:

no _dump_data is defined for class FFI::Pointer

相关内容

最新更新