Sign inSign up

h0tmann/alpine_jpg_to_nextgen

By h0tmann

•Updated 8 months ago

Image
0

2.2K

h0tmann/alpine_jpg_to_nextgen repository overview

⁠Go JPG to Next-Gen Format Converter (Alpine)

A high-performance JPG image converter that uses Alpine Linux native libraries to convert JPG images to modern next-generation formats.

⁠Features

  • Alpine Native Libraries: Uses Alpine's libjxl, libwebp, and libavif packages
  • Shell Execution: Leverages Alpine CLI tools (cjxl, cwebp, avifenc) for conversion
  • Pure Go JPG Encoding: JPG-to-JPG conversion uses Go's standard library
  • No CGo: Simple, pure Go application that shells out to native tools
  • Multi-threaded: Concurrent processing with configurable worker count
  • Configurable: Quality, effort, speed, and format settings via config file

⁠Supported Formats

  • JPG → JPG (Go's image/jpeg encoder)
  • JPG → WebP (Alpine's cwebp)
  • JPG → JXL/JPEG XL (Alpine's cjxl)
  • JPG → AVIF (Alpine's avifenc)

⁠Docker Container

⁠Build
./build_docker.sh

Or manually:

docker build -t go-jpg-to-nextgen:alpine .
⁠Run
docker run -v $(pwd)/0_input:/app/0_input \
           -v $(pwd)/1_jpg_zu_next_gen:/app/1_jpg_zu_next_gen \
           go-jpg-to-nextgen:alpine
⁠Directory Structure
.
├── 0_input/              # Place your JPG files here
├── 1_jpg_zu_next_gen/    # Converted files will appear here
├── config.cfg            # Configuration file
└── processing.log        # Processing log

⁠Configuration (config.cfg)

QUALITY=90              # Quality for all formats (0-100)
WORKERS=0               # Number of workers (0 = auto based on CPU)
BITDEPTH=8              # Bit depth for JPG conversion (8 or 16)
JXL_EFFORT=7            # JXL encoding effort (1-9, higher=slower+better)
AVIF_SPEED=6            # AVIF encoding speed (0-10, higher=faster+lower quality)
FORMATS=webp,jpg,jxl    # Comma-separated list: jpg,webp,jxl,avif

⁠Architecture

⁠No Pure Go Image Libraries

This implementation does not use pure Go image encoding libraries:

  • ❌ chai2010/webp
  • ❌ gen2brain/avif
  • ❌ gen2brain/jpegxl
⁠Alpine Native Tools

Instead, it uses Alpine's native packages:

  • ✅ libjxl + libjxl-tools (provides cjxl command)
  • ✅ libwebp + libwebp-tools (provides cwebp command)
  • ✅ libavif + libavif-apps (provides avifenc command)
⁠Conversion Flow
  1. JPG → WebP: cwebp input.jpg -q 90 -o output.webp
  2. JPG → JXL: cjxl input.jpg output.jxl -q 90 -e 7
  3. JPG → AVIF: avifenc -q 10 -s 6 input.jpg output.avif
  4. JPG → JPG: Go decode → re-encode with image/jpeg
⁠Why This Approach?
  • Better Quality: Native tools are optimized by format experts
  • Faster: Direct JPG→format conversion (no intermediate decode/re-encode)
  • Simpler: No CGo complexity, easier to maintain
  • Smaller: No need to compile C libraries into Go binary

⁠Building Locally (Without Docker)

Requires Alpine Linux or Alpine-compatible environment:

# Install dependencies
apk add go libjxl-tools libwebp-tools libavif-apps

# Build
go build -o go_jpg_to_nextgen main.go

# Run
./go_jpg_to_nextgen

⁠Technical Details

  • Language: Go 1.25+
  • Base Image: Alpine Linux 3.23
  • CGo: Disabled (CGO_ENABLED=0)
  • Binary Size: ~10-15 MB (static Go binary)
  • Container Size: ~100-150 MB (Alpine + libraries + tools)

⁠License

See project license file.

Tag summary

Content type

Image

Digest

sha256:a8bd80a13…

Size

15.3 MB

Last updated

8 months ago

docker pull h0tmann/alpine_jpg_to_nextgen