LMS Image Enhancer

is a package to improve image handling for cover and artist pictures by replacing the bundled Image::Scale perl module.
The included stand-alone image server can also be used without LMS to process local images.

Note

Superseded by LMS Image Handler

Features

  • replaces the PNG/JPG image formats with WebP1
    • better image quality
    • smaller image file size → faster network transfer, smaller LMS database sizes
  • uses superior algorithms for up- and down-scaling
    • better image quality
    • faster down-scaling
  • can use smart crop to generate square images (optionally with round corners)
    • general: attention-based area selection
    • for artists: face detection to select areas, can arrange faces in a square grid 2
  • can use content-aware image resizing 2
  • no forced JPG→PNG conversions3
  • server-side upscaling4
  • stand-alone image server (local or network) and CLI client

Status

  • beta quality
  • only tested on Linux, unlikely to run on any non-Unix OS

Performance

  • generally slower than the standard LMS mechanism
    • higher quality algorithms
    • better image compression (WebP vs. PNG)
    • upscaling enabled
  • face detection can take several seconds on large images / slow hardware (can be disabled)
  • content-aware image resizing (can be disabled)
    • Liquid Rescale is fairly fast
    • C.A.I.R. is slower

Note, however, that images are cached in LMS' databases after processing, so any subsequent access will be near instantaneous (especially when using the LMS DB Optimizer plugin).

Requirements

The only requirement for the module-only version is libvips (V8.10.x, with support for JPEG, PNG, WebP and SVG).
It’s available in most Linux package repositories, so it should be easy to install. If you can't find it, check repology.
If you want to use the stand-alone image server (scaleserver, see below), protobuf-c and nanomsg-NG have to be installed as well.
For content-aware image resizing, there are are two options: C.A.I.R. and Liquid Rescale. The latter needs liblqr installed.

Downloads

version 0.0.9 (perl module, scaleserver, scaleclient)

Installation

Plugin

In the LMS web interface in Settings > Plugins, add https://www.nexus0.net/pub/sw/lmsimgoptim/repo.xml to the list of Additional Repositories, activate the plugin and re-start LMS.

Perl module
  • install libvips
  • identify perl version and architecture
$  perl -v
This is perl 5, version 30, subversion 3 (v5.30.3) built for armv7l-linux-thread-multi-64int
  • find out where the original Scale.so module is located
$ find /usr/share/ -name Scale.so
/usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/Scale.so
/usr/share/squeezeboxserver/CPAN/arch/5.28/armv7l-linux-thread-multi-64int/auto/Image/Scale/Scale.so
  • make a backup (adjust for your perl version and architecture)
$ sudo cp -p /usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/Scale.so /usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/Scale.so~
  • replace the module (adjust for your perl version / architecture, LMS user)

either stand-alone version

$ sudo cp -i imagescale-vips-bin-*/module-standalone/perl5.30/armv7l-linux-thread-multi-64int/Scale.so /usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/
$ sudo chown squeezeboxserver:squeezeboxserver /usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/Scale.so 

or scaleserver version

$ sudo cp -i imagescale-vips-bin-*/module-scaleserver/perl5.30/armv7l-linux-thread-multi-64int/Scale.so /usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/
$ sudo chown squeezeboxserver:squeezeboxserver /usr/share/squeezeboxserver/CPAN/arch/5.30/armv7l-linux-thread-multi-64int/auto/Image/Scale/Scale.so 
  • restart LMS and check the server log
Plugins::LMSimgopt::Plugin::initPlugin (72) LMSimgopt: vips version: 8.10.6
Plugins::LMSimgopt::Plugin::initPlugin (89) LMSimgopt: initialized (v0.0.1)
scaleserver (optional)
  • (install libvips)
  • install the protobuf-c and libnng packages (should be available from your package manager (e.g. Debian: libprotobuf-c and libnng), otherwise check the homepages: protobuf-c / nng)
  • install the liblqr package
  • copy the supplied binary and configuration (adjust for your architecture):
$ sudo cp -i imagescale-vips-bin-*/scaleserver/bin/scaleserver-armv7l /usr/local/bin/scaleserver
$ sudo cp -i imagescale-vips-bin-*/scaleserver/etc/imagescale.ini /usr/local/etc/
  • try starting the server (exit with ^c):
/usr/local/bin/scaleserver /usr/local/etc/imagescale.ini
scaleclient (optional)
  • install the protobuf-c and libnng packages
  • copy the supplied binary
$ sudo cp -i imagescale-vips-bin-*/scaleclient/bin/scaleclient-armv7l /usr/local/bin/scaleclient

Usage

Configuration

If you want to change the defaults (smart crop enabled, square corners etc.), copy the supplied scaleserver/etc/imagescale.ini to /usr/local/etc/imagescale.ini and adjust the values. This file is read by the plugin, the perl module, and scaleserver.

scaleserver

is a stand-alone image processing server which can run on the same or a different computer as LMS.
Arguments:

scaleserver /usr/local/etc/imagescale.ini

It reads a configuration file in the same format as the perl module. If both run on the same server, use the same file. If not, the transport option will be different:

  • on the server: tcp://:<port> e.g. transport = tcp://:3456
  • on the client: tcp://<server>:<port> e.g. transport = tcp://192.168.1.211:3456

You should configure your system to start scaleserver before LMS. How this is done will depend on which service manager your system uses (OpenRC, SystemD, etc.). See imagescale-vips-bin-*/scaleserver/svc for some sample configurations.

scaleclient is a CLI client to submit local files to scaleserver for processing. Run scaleclient -h for help (and read imagescale.ini for an explanation of the values).

scaleclient --format='.webp[Q=80,smart_subsample=TRUE,reduction_effort=6,min_size=TRUE]' --width=300 ipc:///tmp/scaleserver.sock input.jpg output.webp

Building

If on Debian/Ubuntu, install libvips-dev (and libprotobuf-c-dev / libnng-dev if you plan to use scaleserver or scaleclient).

Magic Kernel

Download the sources from John Costella's website.

mkdir magickernel && cd magickernel
tar xf ../magic-kernel-sharp.tar.gz

edit Makefile:

CC = clang # change to gcc if clang is not installed
CFLAGS/$(OPT) = -O3 -pipe -flto -fomit-frame-pointer -fPIC # add -march=native -mtune=native if using gcc

build library:

make -j4 all
cd build/opt/obj/
ar cru libmagickernel.a ByteImage.o DoubleImage.o ExternalFile.o File.o Kernel.o Lock.o MemoryFile.o Random.o TextFile.o bits.o byte_image_file.o double_image_kernel.o erf.o jpc.o jpeg_file.o log.o magic.o magic_double_image.o md5.o normal.o numbers.o parallel.o png_file.o processors.o qsortx.o sinc.o spawn.o strng.o temp_filename.o utc.o
ranlib libmagickernel.a
Perl module

The module can be configured by editing Image-Scale-0.14/Makefile.PL:

$DEFINES .= ' -DMKERNEL_UPSCALE';
$DEFINES .= ' -DFORCE_UPSCALE';
$DEFINES .= q( -DUSE_INI -DINI_PATH="\"/usr/local/etc/imagescale.ini\"");
$DEFINES .= ' -DDEFAULT_SMARTCROP -DDEFAULT_CORNER_ROUND_SELECTIVE';
$DEFINES .= q( -DUSE_SCALESERVER -DSCALESERVER_TRANSPORT="\"/ipc:///tmp/scaleserver.sock\"");

then:

cd Image-Scale-0.14
perl Makefile.PL INSTALL_BASE=./build --with-mk-libs=../magickernel/build/opt/obj/ --with-mk-includes=../magickernel/lib
make install

the module will be in

./build/lib/perl5/<arch>/auto/Image/Scale/Scale.so
Image server
cd scaleserver

review the Makefile

# use -DSEAMCARVE_LQR or -DSEAMCARVE_CAIR, not both
FEATURES := -DMKERNEL_UPSCALE -DUSE_FACEDETECT -DUSE_SEAMCARVE -DSEAMCARVE_LQR -D_SEAMCARVE_CAIR -DCAIR_USE_THREADS -DNUM_CAIR_THREADS=2 -DIMAGE_DUMP -DLOG_USE_COLOR
# for x64_64
#SIMDFLAGS := -D_ENABLE_AVX2
# for ARM
SIMDFLAGS += -D_ENABLE_NEON
OPTFLAGS := -march=native -mtune=native -O2 $(SIMDFLAGS)

Note that if you want to enable NEON (to speed up face detection on ARM), you have to use clang instead of gcc.
Then:

make && strip --strip-unneeded build/bin/scaleserver
CLI client
cd scaleclient
make && strip --strip-unneeded build/bin/scaleclient

API

A JSON/RPC API is available at http://lmsserver:9000/plugins/LMSimgopt/js.html?cmd= where cmd can have the following values:

  • getVipsInfo

Example: wget -q -O - "http://lmsserver:9000/plugins/LMSimgopt/js.html?cmd=getVipsInfo"

FAQ

How do I know if it's actually installed / doing something?
Check in LMS web interface (Settings/Plugins), and the server log for Plugins::LMSimgopt::Plugin entries. Or use the getVipsInfo API command. scaleserver has it's own log file (default /var/log/scaleserver.log).
After the installation, why is there a mix of image formats / styles ?
Images already cached by LMS will not be affected. You can force LMS to regenerate images by deleting it's artwork.db and imgproxy.db while it is not running.
Will this lower stability?
Maybe

Credits

License

EUPL-1.2


  1. see also: browser support 

  2. requires the use of the stand-alone image server 

  3. LMS converts any JPG which isn't perfectly square (e.g. 700x701 pixels) to PNG, which results in huge file sizes 

  4. LMS doesn't upscale images, relying instead on the client (e.g. browser) to do so