Skip to content

Advanced real-time image optimization with mozjpeg on your server - WordPress plugin

Notifications You must be signed in to change notification settings

szepeviktor/image-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Image Factory

Advanced real-time image optimization with mozjpeg on your server.

This project uses JPEG Archive by Daniel G. Taylor which depends on mozjpeg, an improved JPEG encoder.

Install dependencies and background worker

apt-key adv --keyserver pgp.mit.edu --recv-keys 451A4FBA
echo "deb http://szepeviktor.github.io/debian/ jessie main" > /etc/apt/sources.list.d/szepeviktor.list
apt-get update && apt-get install -y socat optipng jpeginfo jpeg-archive
cp -a ./bin/image-factory-worker.sh /usr/local/bin/

Install init script and options

Source: https://github.com/asaif/socat-init

Replace www-data (in 3 places) with the PHP user.

cp -a ./init.d/socat /etc/init.d/
cat > /etc/default/socat.conf <<<EOF
SOCAT_DEFAULTS="-d -d -d -ly"
OPTIONS="UNIX-LISTEN:/var/www/above-document-root/factory.sock,mode=600,fork,user=www-data,group=www-data EXEC:/usr/local/bin/image-factory-worker.sh,pipes,su=www-data"
EOF
update-rc.d socat defaults

Optional second instance.

cp -a ./init.d/socat /etc/init.d/socat02
sed -i 's;/etc/default/socat\.conf;/etc/default/socat02.conf;' /etc/init.d/socat02
cat > /etc/default/socat02.conf <<<EOF
SOCAT_DEFAULTS="-d -d -d -ly"
OPTIONS="UNIX-LISTEN:/var/www/other-document-root/factory.sock,mode=600,fork,user=www-data,group=www-data EXEC:/usr/local/bin/image-factory-worker.sh,pipes,su=www-data"
EOF
update-rc.d socat02 defaults

Setting Socket path

The Socket path option is on the Settings / Media page.

Or you could add a define to your wp-config.php:

define( 'IMAGE_FACTORY_SOCKET', '/var/www/site/factory.sock' );

Manual test

wp option add "image_factory_socket" "/var/www/above-document-root/factory.sock" --autoload=no
/usr/bin/socat UNIX-LISTEN:/var/www/above-document-root/factory.sock,mode=600,fork,user=www-data,group=www-data EXEC:/usr/local/bin/image-factory-worker.sh,pipes,su=www-data

Now upload a JPEG image to Media Library and watch syslog:

tail -f /var/log/syslog

TODO

Support systemd.

About

Advanced real-time image optimization with mozjpeg on your server - WordPress plugin

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published