janko / image_processing

High-level image processing wrapper for libvips and ImageMagick/GraphicsMagick
MIT License
863 stars 76 forks source link

Size of watermark (Vips) #110

Open 9mm opened 1 year ago

9mm commented 1 year ago

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

janko commented 3 months ago

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.