diff --git a/README.md b/README.md index 6e6eecbf..b26d4e25 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,7 @@ The compilation of some extensions may be fine-tuned to better fit your needs by | Extension | Environment variable | Description | |---|---|---| | lzf | IPE_LZF_BETTERCOMPRESSION=1 | By default `install-php-extensions` compiles the `lzf` extension to prefer speed over size; you can use this environment variable to compile it preferring size over speed | +| gd | IPE_GD_WITHOUTAVIF=1 | Since PHP 8.1, gd supports the AVIF format. Enabling it requires compiling libaom and/or libavif, which requires some time. You can disable AVIF support by setting this environment variable | ## Special requirements diff --git a/install-php-extensions b/install-php-extensions index 2e74ecae..a96b88ce 100755 --- a/install-php-extensions +++ b/install-php-extensions @@ -501,6 +501,16 @@ buildRequiredPackageLists() { else buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libwebp" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libwebp-dev" + if test $PHP_MAJMIN_VERSION -ge 801; then + if ! isLibaomInstalled || ! isLibavifInstalled; then + case "${IPE_GD_WITHOUTAVIF:-}" in + 1 | y* | Y*) ;; + *) + buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile cmake nasm" + ;; + esac + fi + fi fi ;; gd@debian) @@ -512,6 +522,16 @@ buildRequiredPackageLists() { else buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent ^libwebp[0-9]+$" buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libwebp-dev" + if test $PHP_MAJMIN_VERSION -ge 801; then + if ! isLibaomInstalled || ! isLibavifInstalled; then + case "${IPE_GD_WITHOUTAVIF:-}" in + 1 | y* | Y*) ;; + *) + buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile cmake nasm" + ;; + esac + fi + fi fi ;; gearman@alpine) @@ -1299,8 +1319,8 @@ installOracleInstantClient() { # Check if the Microsoft SQL Server ODBC Driver is installed # # Return: -# 0 (true): if the string is in the list -# 1 (false): if the string is not in the list +# 0 (true) +# 1 (false) isMicrosoftSqlServerODBCInstalled() { test -d /opt/microsoft/msodbcsql*/ } @@ -1331,6 +1351,61 @@ installMicrosoftSqlServerODBC() { esac } +# Check if libaom is installed +# +# Return: +# 0 (true) +# 1 (false) +isLibaomInstalled() { + if ! test -f /usr/local/lib/libaom.so && ! test -f /usr/lib/libaom.so; then + return 1 + fi + if ! test -f /usr/local/include/aom/aom_codec.h && ! test -f /usr/include/aom/aom_codec.h; then + return 1 + fi + return 0 +} + +# Install libaom +installLibaom() { + printf 'Installing libaom\n' + installLibaom_tmp="$(pwd)" + cd "$(getPackageSource https://aomedia.googlesource.com/aom/+archive/v3.1.1.tar.gz)" + mkdir my.build + cd my.build + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1 -DENABLE_DOCS=0 -DENABLE_EXAMPLES=0 -DENABLE_TESTDATA=0 -DENABLE_TESTS=0 -DENABLE_TOOLS=0 .. + make -j$(getProcessorCount) install + cd "$installLibaom_tmp" + ldconfig || true +} + +# Check if libavif is installed +# +# Return: +# 0 (true) +# 1 (false) +isLibavifInstalled() { + if ! test -f /usr/local/lib/libavif.so && ! test -f /usr/local/lib/libavif.so; then + return 1 + fi + if ! test -f /usr/local/include/aom/aom_codec.h && ! test -f /usr/include/aom/aom_codec.h; then + return 1 + fi + return 0 +} + +# Install libavif +installLibavif() { + printf 'Installing libavif\n' + installLibavif_tmp="$(pwd)" + cd "$(getPackageSource https://codeload.github.com/AOMediaCodec/libavif/tar.gz/refs/tags/v0.9.2)" + mkdir my.build + cd my.build + cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DAVIF_CODEC_AOM=ON + make -j$(getProcessorCount) install + cd "$installLibavif_tmp" +} + # Install Composer installComposer() { installComposer_version="$(getWantedPHPModuleVersion @composer)" @@ -1421,8 +1496,25 @@ EOF docker-php-ext-configure gd --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf --with-webp-dir elif test $PHP_MAJMIN_VERSION -le 703; then docker-php-ext-configure gd --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-xpm-dir --with-freetype-dir --with-webp-dir - else + elif test $PHP_MAJMIN_VERSION -le 800; then docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype + else + case "${IPE_GD_WITHOUTAVIF:-}" in + 1 | y* | Y*) ;; + *) + if ! isLibaomInstalled; then + installLibaom + fi + if ! isLibavifInstalled; then + installLibavif + fi + ;; + esac + if isLibaomInstalled && isLibavifInstalled; then + docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype --with-avif + else + docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype + fi fi ;; gmp) diff --git a/scripts/tests/gd b/scripts/tests/gd index 16d2d549..1d463530 100755 --- a/scripts/tests/gd +++ b/scripts/tests/gd @@ -32,9 +32,10 @@ $formats = [ 'gd', ]; if (PHP_VERSION_ID >= 70200) { - $formats = array_merge($formats, [ - 'bmp', - ]); + $formats[] = 'bmp'; + if (PHP_VERSION_ID >= 80100) { + $formats[] = 'avif'; + } } $tempFile = null; $image2 = null;