JPEG image compress watcher based Filesystem event notification github.com/rjeczalik/notify
Example compress quality 82%
original before size 1.47 MB (1,536,181 bytes) | compressed after 277.56 KB (284,223 bytes) |
---|---|
Installation dependency
~ $ apt install libmagickwand-dev imagemagick
Install TinyJPG for v0.0.9:
curl -L https://raw.githubusercontent.com/OrlovEvgeny/TinyJPG/master/tinyjpg_install.sh | sh -s - v0.0.9
If you prefer Ansible:
tasks:
- name: TinyJPG installed
sudo: yes
shell: "curl -L https://raw.githubusercontent.com/OrlovEvgeny/TinyJPG/master/tinyjpg_install.sh | sh -s - v0.0.9"
Edit config File
~ $ vim /etc/tinyjpg/config.yml
##
# TinyJPG v0.0.9
#
# worker - maximum amount workers, Default value - 5
# verbose - verbose log, Default value - true
# worker_buffer - maximum buffer queue workers, Default value - 100
# event_buffer - maximum buffer an event reported by the underlying filesystem notification subsystem, Default value - 100
##
general:
worker: 5
worker_buffer: 100
event_buffer: 300
verbose: false
error_log: '/var/log/tinyjpg/error.log'
info_log: '/var/log/tinyjpg/info.log'
###
# Image compress settings
#
# paths - directories you need to track
# prefix - prefix of files to be processed, Default value all files - *
# example use
#
# prefix:
# - 'orig'
# - 'medium'
# - 'full'
#
# quality - This param image quality level in percentage.
# If the original image quality is lower than the quality of the parameter - quality
# the image will not be processed
###
compress:
paths:
- '/home/www/example.com/uploads'
- '/home/www/site.org/uploads'
prefix:
- '*'
quality: 82
check that everything is fine
~ $ tinyjpg -help
Usage of build/tinyjpg:
-config string
config file path
-event_buffer int
buffer an event reported (default 300)
-path string
uploads folder path, default - /home/www (default "/home/www")
-quality int
image quality level in percentage (default 82)
-worker int
maximum amount workers (default 5)
-worker_buffer int
maximum buffer queue workers (default 500)
I recommend using supervisor
example config
~ $ vim /etc/supervisor/conf.d/tinyjpg.conf
write
[program:tinyjpg]
command=/usr/local/bin/tinyjpg -config=/etc/tinyjpg/config.yml
environment=ENVIRONMENT=production
autorestart=true
user=root
redirect_stderr=true
stderr_logfile=/var/log/tinyjpg/log.err.log
stdout_logfile=/var/log/tinyjpg/log.out.log
~ $ mkdir -p /var/log/tinyjpg
~ $ service supervisor restart
or use Tmux
~ $ tinyjpg -config=/etc/tinyjpg/config.yml
or use CLI mode
# deprecated
~ $ tinyjpg -path=/home/www/example.com/images -worker=10
Args:
- path - required. Path to watch new files, default /home/www
- worker - optional. Amount start workers process, default 5
For compilation you need to install Golang1.8
~ $ apt install libmagickwand-dev imagemagick
~ $ git clone https://github.com/OrlovEvgeny/TinyJPG && cd TinyJPG
~ $ go get -u github.com/rjeczalik/notify
~ $ mkdir build && go build -o ./build/tinyjpg *.go
~ $ mv /build/tinyjpg /usr/local/bin/tinyjpg
permission for execution
~ $ chmod +x /usr/local/bin/tinyjpg