Software Development

Dynamic Watermarking With IMGProxy and Apache APISIX – Insta News Hub

Dynamic Watermarking With IMGProxy and Apache APISIX – Insta News Hub

Final week, I described how to add a dynamic watermark to your images 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 will need to seek for an present 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 elements, particularly imgproxy and Apache APISIX. I already mixed them to resize images on-the-fly.

This is the overall sequence circulate of the method:

Dynamic Watermarking With IMGProxy and Apache APISIX – Insta News Hub

  • 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

For example 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 online server
  2. Watermark photos route
  3. Rewrite the URL…
  4. …with an imgproxy-configured route and…
  5. …ahead to imageproxy

You will discover the precise rewritten URL syntax in imgproxy documentation. The watermark itself is configured by way of a single setting variable. You can purchase imgproxy‘s Professional model when you want totally different watermarks. As a poor man’s different, you could possibly additionally arrange totally 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 feel they make a match made in Heaven.

The whole supply code for this submit will be discovered on GitHub.

To Go Additional