1

I want to show watermarked PDF file to end user on .erb view file on my application. For testing purpose firstly i tried to do this with jpeg image. My resources are;

  1. ImageProcessing Gem
  2. ActiveStorage
  3. Vips Gem

This code is works but not yet watermarked.

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

This code is not working. Error is 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? %>

Also i tried another approach which is not working too. Error is 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? %>

This is not working too. Error is like 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? %>

1 Answers1

1

I was able to get it to work with the following code.

In the controller:

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

Then in the view:

<%= 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: "" %>

I think that earlier, I was trying to load the image by reading the file instead of just providing the pathname (sth like water = ImageProcessing::Vips.Image.new(full_path), and that was when I was getting the same error:

no _dump_data is defined for class FFI::Pointer
umar
  • 4,309
  • 9
  • 34
  • 47