Optimizing uploaded images
Users can upload images for channels. Large images are not automatically scaled by Notifly and can take up unnecessary disk space and network bandwidth. The script below will resize all images so that their maximum dimension, i.e. width and/or height, is 512 pixels. Smaller images will not be resized.
PNG images will be optimized for file size without loss of quality.
Once a file has been resized/optimized, it will not be resized/optimized again later.
Prerequisites
Section titled “Prerequisites”Install
Script
Section titled “Script”Create a script, for example /opt/notifly/optimize-images.sh containing
#!/usr/bin/env bashset -e
DATA=/home/jm/src/Notifly/data
for FILE in "$DATA"/images/*; do if [ "$FILE" -nt "$DATA"/images-optimized ]; then EXT=$(echo "${FILE##*.}"|tr '[:upper:]' '[:lower:]') if [ "$EXT" = png -o "$EXT" = jpg -o "$EXT" = jpeg -o "$EXT" = gif ]; then convert "$FILE" -resize "512>" "$FILE" fi if [ "$EXT" = png ]; then optipng "$FILE" fi fidonetouch "$DATA"/images-optimizedNote that if $DATA/images-optimized is missing, all files will be selected for resizing and optimization.
Run the following commands on the script
sudo chmod go-rw /opt/notifly/optimize-images.shsudo chmod u+x /opt/notifly/optimize-images.shYou can test the script by running it manually. Having a backup of the data directory beforehand is always recommended.
Scheduling
Section titled “Scheduling”Add the following line to a file, for example /etc/cron.d/notifly
12 12 * * * root /opt/notifly/optimize-images.sh