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.