Dynamic Watermarking With IMGProxy and Apache APISIX – DZone – Uplaza

Final week, I described how you can add a dynamic watermark to your photographs on the JVM. I did not discover any library, so I needed to develop the function, or, extra exactly, an embryo of a function, on my own. Relying in your tech stack, you have to seek for an current library or roll up your sleeves. For instance, Rust presents such an out-of-the-box library. Worse, this method could be not possible to implement if you do not have entry to the supply picture.

One other different is to make use of ready-made parts, specifically imgproxy and Apache APISIX. I already mixed them to resize photographs on-the-fly.

Here is the final sequence stream of the method:

  • When APISIX receives a selected sample, it calls imgproxy with the related parameters
  • imgproxy fetches the unique picture and the watermark to use
  • It watermarks the unique picture and returns the consequence to APISIX

As an instance the sample is /watermark/*.

We will outline two routes:

routes:
  - uri: "*"                                                                     #1
    upstream:
      nodes:
        "server:3000": 1
  - uri: /watermark/*                                                            #2
    plugins:
      proxy-rewrite:                                                             #3
        regex_uri:
          - /watermark/(.*)
          - /dummy_sig/watermark:0.8:nowe:20:20:0.2/plain/http://server:3000/$1  #4
    upstream:
      nodes:
        "imgproxy:8080": 1                                                       #5
  1. Catch-all route that forwards to the net server
  2. Watermark photographs route
  3. Rewrite the URL…
  4. …with an imgproxy-configured route and…
  5. …ahead to imageproxy

You could find the precise rewritten URL syntax in imgproxy documentation. The watermark itself is configured by way of a single surroundings variable. You can purchase imgproxy‘s Professional model should you want completely different watermarks. As a poor man’s different, you can additionally arrange completely different situations, every with its watermark, and configure APISIX to route the request to the specified occasion.

On this submit, we applied a watermarking function with the assistance of imgproxy. The extra I give it some thought, the extra I believe they make a match made in Heaven.

The entire supply code for this submit might be discovered on GitHub.

To Go Additional

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version