Skip to content

Commit acb28b3

Browse files
authored
build(docker): Docker mozjpeg variant for imagor (#613)
* build(docker): Docker mozjpeg variant for imagor * build(docker): Docker mozjpeg variant for imagor * build(docker): Docker mozjpeg variant for imagor * build(docker): Docker mozjpeg variant for imagor * build(docker): Docker mozjpeg variant for imagor * build(docker): Docker mozjpeg variant for imagor * chore: add community section to readme * add readme
1 parent a28f783 commit acb28b3

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

.github/workflows/docker-imagor-magick.yml renamed to .github/workflows/docker-variants.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: docker-imagor-magick
1+
name: docker-variants
22

33
on:
44
push:
@@ -7,14 +7,22 @@ on:
77
tags: [ 'v*.*.*' ]
88

99
jobs:
10-
build:
11-
name: Docker imagor-magick
10+
build-variants:
11+
name: Docker variants
1212
runs-on: ubuntu-latest
1313
if: github.repository == 'cshum/imagor'
1414
permissions:
1515
contents: read
1616
packages: write
17-
17+
strategy:
18+
matrix:
19+
variant:
20+
- name: magick
21+
build_args: |
22+
ENABLE_MAGICK=true
23+
- name: mozjpeg
24+
build_args: |
25+
ENABLE_MOZJPEG=true
1826
steps:
1927
- name: Checkout repository
2028
uses: actions/checkout@v3
@@ -38,7 +46,7 @@ jobs:
3846
id: meta
3947
uses: docker/metadata-action@v4
4048
with:
41-
images: ghcr.io/cshum/imagor-magick
49+
images: ghcr.io/cshum/imagor-${{ matrix.variant.name }}
4250
tags: |
4351
type=ref,event=branch
4452
type=semver,pattern={{version}}
@@ -52,5 +60,4 @@ jobs:
5260
push: true
5361
tags: ${{ steps.meta.outputs.tags }}
5462
labels: ${{ steps.meta.outputs.labels }}
55-
build-args: |
56-
ENABLE_MAGICK=true
63+
build-args: ${{ matrix.variant.build_args }}

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@ FROM golang:${GOLANG_VERSION}-trixie as builder
33

44
ARG VIPS_VERSION=8.17.2
55
ARG TARGETARCH
6+
67
ARG ENABLE_MAGICK=false
78

9+
ARG ENABLE_MOZJPEG=false
10+
ARG MOZJPEG_VERSION=4.1.1
11+
ARG MOZJPEG_URL=https://github.com/mozilla/mozjpeg/archive
12+
813
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
914

15+
# Conditionally install MozJPEG build dependencies and build MozJPEG
16+
RUN if [ "$ENABLE_MOZJPEG" = "true" ]; then \
17+
DEBIAN_FRONTEND=noninteractive \
18+
apt-get update && \
19+
apt-get install --no-install-recommends -y build-essential libboost-all-dev pkg-config autoconf automake libtool nasm make cmake flex libpng-tools libpng-dev zlib1g-dev && \
20+
cd /tmp && \
21+
curl -fsSLO ${MOZJPEG_URL}/v${MOZJPEG_VERSION}.tar.gz && \
22+
tar xf v${MOZJPEG_VERSION}.tar.gz && \
23+
cd mozjpeg-${MOZJPEG_VERSION} && \
24+
cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local . && \
25+
make -j4 && \
26+
make install && \
27+
cp jpegint.h /usr/include/jpegint.h && \
28+
cd .. && \
29+
rm -rf mozjpeg-${MOZJPEG_VERSION} v${MOZJPEG_VERSION}.tar.gz; \
30+
fi
31+
1032
# Installs libvips + required libraries + conditionally ImageMagick
1133
RUN DEBIAN_FRONTEND=noninteractive \
1234
apt-get update && \
@@ -56,6 +78,7 @@ FROM debian:trixie-slim as runtime
5678
LABEL maintainer="adrian@cshum.com"
5779

5880
ARG ENABLE_MAGICK=false
81+
ARG ENABLE_MOZJPEG=false
5982

6083
COPY --from=builder /usr/local/lib /usr/local/lib
6184
COPY --from=builder /etc/ssl/certs /etc/ssl/certs

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,49 @@ docker run -p 8000:8000 ghcr.io/cshum/imagor-magick -imagor-unsafe -imagor-auto-
438438

439439
We recommend using the standard imagor image for most use cases.
440440

441+
### MozJPEG Support
442+
443+
By default, imagor uses libjpeg-turbo for JPEG encoding, which provides fast compression. For enhanced JPEG compression at the cost of slower encoding speed, imagor provides a MozJPEG-enabled variant that includes [MozJPEG](https://github.com/mozilla/mozjpeg) support through libvips.
444+
445+
MozJPEG improves JPEG compression efficiency while maintaining compatibility with existing JPEG decoders. It can typically reduce JPEG file sizes by 10-15% compared to libjpeg-turbo while maintaining the same visual quality, but with slower encoding performance.
446+
447+
#### Docker build `imagor-mozjpeg`
448+
449+
```bash
450+
docker pull ghcr.io/cshum/imagor-mozjpeg
451+
```
452+
453+
Usage:
454+
455+
```bash
456+
docker run -p 8000:8000 ghcr.io/cshum/imagor-mozjpeg -imagor-unsafe -vips-mozjpeg
457+
```
458+
459+
#### Enabling MozJPEG
460+
461+
MozJPEG can be enabled using the `-vips-mozjpeg` command-line argument, or the equivalent environment variable:
462+
463+
```bash
464+
VIPS_MOZJPEG=1
465+
```
466+
467+
Docker Compose example:
468+
469+
```yaml
470+
version: "3"
471+
services:
472+
imagor:
473+
image: ghcr.io/cshum/imagor-mozjpeg:latest
474+
environment:
475+
PORT: 8000
476+
IMAGOR_UNSAFE: 1
477+
VIPS_MOZJPEG: 1 # Enable MozJPEG compression
478+
ports:
479+
- "8000:8000"
480+
```
481+
482+
When enabled, MozJPEG will be used for JPEG output, providing better compression efficiency for JPEG images.
483+
441484
### Metadata and Exif
442485

443486
imagor provides metadata endpoint that extracts information such as image format, resolution and Exif metadata.

0 commit comments

Comments
 (0)