image_processing icon indicating copy to clipboard operation
image_processing copied to clipboard

Size of watermark (Vips)

Open 9mm opened this issue 2 years ago • 1 comments

I have the following:

    has_one_attached :cover_image do |image|
      image.variant :square_medium,
        format: 'jpg',
        resize_to_fill: [600, 600],
        composite: ['app/assets/images/watermark.png', {
          gravity: 'south-west',
          offset: [10, 10],
        }],
        saver: { subsample_mode: 'on', strip: true, quality: 85 }
    end

How would I change the width of the overlay? I notice regardless of what size the image is it always appears to be the same size on the watermark.

Based on the docs it seems like something like this Vips::Image.new_from_file('app/assets/images/watermark.png') would work but that raises an exception.

Thanks

Edit: Nevermind on "same size", it would appear that is ActiveStorage caching/hashing arguments. Still it would be really nice to dynamically size it

9mm avatar Apr 05 '23 14:04 9mm

Active Storage doesn't support dynamic processing, you have to encode everything at the time you're generating the link. It would be great if Active Storage supported registering custom operations, similar to what Shrine does. Some block that would yield an ImageProcessing::Builder instance or a Vips::Image object and allow hooking into the processing pipeline, which would be called when the operation is being applied.

I know I'm replying late, but what would the composition look like performed directly on Vips::Image (without Active Storage)? That would help me understand what needs to be done better.

janko avatar Jun 17 '24 08:06 janko