Nginx

Watermark your website images using nginx JPEG module

by ,


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install nginx, Varnish and lots of useful modules for them, this is your one stop repository to get all performance related software.
You have to maintain an active subscription in order to be able to use the repository!

At times, you need to protect your images with a logo or watermark. How can you do this on the fly without processing all images? Meet modjpeg-nginx.

modjpeg-nginx is nginx filter module for adding overlays on JPEGs on-the-fly with libmodjpeg.

Install modjpeg-nginx in CentOS / RedHat 7

yum -y install https://extras.getpagespeed.com/release-el7-latest.rpm
yum install nginx-module-jpeg

This will install both nginx and the dynamic module of modjpeg-nginx. If you were using our repository before, only the dynamic module will be installed.

Configure nginx to load the module

load_module modules/ngx_http_jpeg_filter_module.so;

Add watermark / logos to all images

location /img/ {
   # enable jpeg filter module
   jpeg_filter on;

   # limit image sizes to 9 megapixel
   jpeg_filter_max_pixel 9000000;

   # limit image file size to 5 megabytes
   jpeg_filter_buffer 5M;

   # deliver the images unmodified if one of the limits apply
   jpeg_filter_graceful on;

   # pixelate the image
   jpeg_filter_effect pixelate;

   # add a masked logo in the bottom right corner
   # with a distance of 10 pixel from the border
   jpeg_filter_dropon_align bottom right;
   jpeg_filter_dropon_offset -10 -10;
   jpeg_filter_dropon_file /path/to/logo.jpg;
}

You can actually combine this module with PageSpeed module. The latter will cache watermarked images if you use filters for optimizing images.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.