Skip to content

Commit

Permalink
Merge branch 'feature/imagick-vips'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.reuse/dep5
  • Loading branch information
joppuyo committed Aug 6, 2022
2 parents 79ffcc6 + b718ad3 commit ff095fa
Show file tree
Hide file tree
Showing 35 changed files with 1,117 additions and 196 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,41 @@ jobs:
with:
files: ./tests/_output/coverage.xml
verbose: true
test-linux-imagemagick:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- run: docker-compose pull
- uses: satackey/[email protected]
continue-on-error: true
- name: Setup docker
run: docker-compose --file docker-compose-imagemagick.yml up --build -d
- name: Validate composer.json and composer.lock
run: docker exec -w /home/project jpeg-xl-encode_default_1 bash -c "composer validate"
- name: Install dependencies
run: docker exec -w /home/project jpeg-xl-encode_default_1 bash -c "composer install --prefer-dist --no-progress --no-suggest"
- name: Run test suite
run: docker exec -w /home/project jpeg-xl-encode_default_1 bash -c "export XDEBUG_MODE=coverage; ./vendor/bin/codecept run --debug -vvv --coverage --coverage-xml"
- uses: codecov/codecov-action@v2
with:
files: ./tests/_output/coverage.xml
verbose: true
test-linux-vips:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- run: docker-compose pull
- uses: satackey/[email protected]
continue-on-error: true
- name: Setup docker
run: docker-compose --file docker-compose-vips.yml up --build -d
- name: Validate composer.json and composer.lock
run: docker exec -w /home/project jpeg-xl-encode_default_1 bash -c "composer validate"
- name: Install dependencies
run: docker exec -w /home/project jpeg-xl-encode_default_1 bash -c "composer install --prefer-dist --no-progress && composer require jcupitt/vips"
- name: Run test suite
run: docker exec -w /home/project jpeg-xl-encode_default_1 bash -c "export XDEBUG_MODE=coverage; ./vendor/bin/codecept run --debug -vvv --coverage --coverage-xml"
- uses: codecov/codecov-action@v2
with:
files: ./tests/_output/coverage.xml
verbose: true
4 changes: 2 additions & 2 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/

Files: tests/_data/broadway-tower-edit.jpg "tests/_data/broadway tower edit.jpg" "tests/_data/broadway tower edit.jpg"
Files: tests/_data/broadway-tower-edit/*
Copyright: The author is Newton2 (cropped by Yummifruitbat)
License: CC-BY-2.5
Comment: https://commons.wikimedia.org/wiki/File:Broadway_tower_edit.jpg

Files: tests/_data/jpeg-xl-logo.png "tests/_data/folder with space/jpeg-xl-logo.png"
Files: tests/_data/jpeg-xl-logo/*
Copyright: Masahito TAKIZAWA
License: CC-BY-ND-4.0
Comment: https://jpeg.org/downloads/JPEG_logos_package.zip
Expand Down
68 changes: 68 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,74 @@

FROM php:7.4-cli

RUN apt update && apt install -y \
cmake pkg-config libbrotli-dev \
libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev \
clang git

ENV CC=clang
ENV CXX=clang++

WORKDIR /
RUN git clone https://github.com/libjxl/libjxl.git --recursive && cd /libjxl && git reset --hard tags/v0.6.1
WORKDIR /libjxl/build
RUN cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF ..
RUN cmake --build . -- -j$(nproc)
RUN cmake --install .

# Imagick

RUN apt-get update && apt-get install -y \
libxml2 \
libxml2-dev

RUN mkdir -p /imagick-source \
&& cd /imagick-source \
&& curl "https://download.imagemagick.org/ImageMagick/download/releases/ImageMagick-7.1.0-17.tar.gz" -o imagemagick.tar.gz \
&& tar -xof imagemagick.tar.gz -C /imagick-source --strip-components=1 \
&& rm imagemagick.tar.gz* \
&& ./configure --with-jxl=yes \
&& make \
&& make install \
&& make clean

RUN pecl install imagick && docker-php-ext-enable imagick

# Vips
RUN apt-get update && apt-get install -y \
build-essential \
wget \
pkg-config

# stuff we need to build our own libvips ... this is a pretty random selection
# of dependencies, you'll want to adjust these
RUN apt-get install -y \
glib-2.0-dev \
libexpat-dev \
librsvg2-dev \
libpng-dev \
libgif-dev \
libjpeg-dev \
libexif-dev \
liblcms2-dev \
liborc-dev

ARG VIPS_VERSION=8.12.1
ARG VIPS_URL=https://github.com/libvips/libvips/releases/download

RUN cd /usr/local/src \
&& wget ${VIPS_URL}/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz \
&& tar xf vips-${VIPS_VERSION}.tar.gz \
&& cd vips-${VIPS_VERSION} \
&& ./configure \
&& make \
&& make install

# RUN apt-get install -y \
# php-dev

RUN PKG_CONFIG_PATH=/usr/local/lib/pkgconfig pecl install vips && docker-php-ext-enable vips

RUN apt-get clean
RUN apt-get update

Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ SPDX-License-Identifier: CC0-1.0
[![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/joppuyo/jpeg-xl-encode)](https://packagist.org/packages/joppuyo/jpeg-xl-encode)
[![Packagist License](https://img.shields.io/packagist/l/joppuyo/jpeg-xl-encode)](https://packagist.org/packages/joppuyo/jpeg-xl-encode)
[![REUSE status](https://api.reuse.software/badge/github.com/joppuyo/jpeg-xl-encode)](https://api.reuse.software/info/github.com/joppuyo/jpeg-xl-encode)
[![Active Development](https://img.shields.io/badge/Maintenance%20Level-Actively%20Developed-brightgreen.svg)](https://gist.github.com/cheerfulstoic/d107229326a01ff0f333a1d3476e068d)

A PHP library for encoding JPEG XL images. Supports JPEG and PNG input. Very much inspired by the excellent [WebP Convert](https://github.com/rosell-dk/webp-convert) library.

## Requirements

* PHP 7.2.5 or later.
* Linux, MacOS or Windows OS with x64 architecture.
* The `proc_open` function needs to be enabled in the PHP installation since the library executes the `cjxl` binary on the command line. Some web hosts may disable this function for security reasons.
* Linux, MacOS or Windows OS
* One or more of the following methods of encoding JPEG XL images needs to be avaiable:
* The `proc_open` PHP function needs to be enabled so the library can execute the cjxl binary on the command line.
* The `vips` PHP extension is installed and enabled. VIPS image processing library must be compiled with jxl support
* The `imagick` PHP extension is installed and enabled. ImageMagick library needs to be compiled with jxl support

## Installation

Expand All @@ -36,7 +40,7 @@ $options = [
'quality' => 80,
];
try {
\Joppuyo\JpegXlEncode\Encoder::encode($source, $destination, $options);
\NPX\JpegXlEncode\Encoder::encode($source, $destination, $options);
} catch (Exception $exception) {
error_log('Whoops, something went wrong.');
}
Expand Down Expand Up @@ -73,8 +77,28 @@ Enabling progressive decoding for Modular images is not recommended since it mak

Default value is `true` for lossy and `false` for lossless.

## Methods

There's 3 different methods you can use: cjxl binary, ImageMagick extension and Vips extension. The library goes through each of the available methods and tries to use them. If none of the methods are available, an exception will be thrown.

### Cjxl binary

This method executes the cjxl binary on the command line. It's the most compatible method and it supports the most features. However, the `proc_open` function needs to be enabled in the PHP installation since the library executes the `cjxl` binary on the command line. Some web hosts may disable this function for security reasons.

### ImageMagick extension

This method uses the ImageMagick library and its PHP extension Imagick. However, ImageMagick needs to be built with JXL delegate. In practice, this means you will need to install the libjxl library on the server. Then you will need to build ImageMagick from the source with the option `--with-jxl=yes`. Lastly, you will need to install the Imagick PHP extension. The ImageMagick extension does not support progressive encoding at the time.

### Vips extension

This method uses the vips library and its PHP extension. However, vips needs to be built with JXL support. In practice, this means you will need to install the libjxl library on the server. Then you will need to build vips from the source. Lastly, you will need to install the vips PHP extension. The vips extension does not support progressive encoding at the time.

## License

MIT.

For detailed license information, see the individual file headers and [`.reuse/dep5`](.reuse/dep5).

## Maintance level

This project is under active development and it has a number of features currently under development.
Binary file removed bin/cjxl-v0-5-0-macos-x64-static
Binary file not shown.
Binary file renamed bin/cjxl-v0-5-0-linux-x64-static → bin/cjxl-v0-6-1-linux-x64-static
100644 → 100755
Binary file not shown.
Binary file added bin/cjxl-v0-6-1-macos-x64-static
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"autoload": {
"psr-4": {
"Joppuyo\\": "src/"
"NPX\\": "src/"
}
},
"require": {
Expand All @@ -36,5 +36,8 @@
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.3",
"codeception/module-cli": "^1.1"
},
"suggest": {
"jcupitt/vips": "Required for using the vips method"
}
}
12 changes: 12 additions & 0 deletions docker-compose-imagemagick.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2021 Johannes Siipola
# SPDX-License-Identifier: CC0-1.0

version: "3.9"
services:
default:
build:
context: .
dockerfile: imagemagick.Dockerfile
tty: true
volumes:
- .:/home/project
12 changes: 12 additions & 0 deletions docker-compose-vips.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2021 Johannes Siipola
# SPDX-License-Identifier: CC0-1.0

version: "3.9"
services:
default:
build:
context: .
dockerfile: vips.Dockerfile
tty: true
volumes:
- .:/home/project
50 changes: 50 additions & 0 deletions imagemagick.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2021 Johannes Siipola
# SPDX-License-Identifier: CC0-1.0

FROM php:7.4-cli

RUN apt update && apt install -y \
cmake pkg-config libbrotli-dev \
libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev \
clang git

ENV CC=clang
ENV CXX=clang++

WORKDIR /
RUN git clone https://github.com/libjxl/libjxl.git --recursive && cd /libjxl && git reset --hard tags/v0.6.1 && ./deps.sh
WORKDIR /libjxl/build
RUN cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF ..
RUN cmake --build . -- -j$(nproc)
RUN cmake --install .

# Imagick

RUN apt-get update && apt-get install -y \
libxml2 \
libxml2-dev

RUN mkdir -p /imagick-source \
&& cd /imagick-source \
&& curl "https://imagemagick.org/archive/ImageMagick.tar.gz" -o imagemagick.tar.gz \
&& tar -xof imagemagick.tar.gz -C /imagick-source --strip-components=1 \
&& rm imagemagick.tar.gz* \
&& ./configure --with-jxl=yes \
&& make \
&& make install \
&& make clean

RUN pecl install imagick && docker-php-ext-enable imagick

# Xdebug

RUN apt-get clean
RUN apt-get update

RUN pecl install xdebug && docker-php-ext-enable xdebug

# Composer

RUN apt-get install -y libzip-dev zip && docker-php-ext-install zip

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Loading

0 comments on commit ff095fa

Please sign in to comment.