Watermark your website images using nginx JPEG module

by , , revisited on

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

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 an NGINX filter module for adding overlays on JPEGs on-the-fly with libmodjpeg.

Install modjpeg-nginx in CentOS/RHEL 7

yum -y install https://extras.getpagespeed.com/release-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

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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