Skip to content

Commit

Permalink
Enable AVIF for GD on PHP 8.1
Browse files Browse the repository at this point in the history
Test: gd
  • Loading branch information
mlocati committed Jul 8, 2021
1 parent 6cf665a commit 7b609ff
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
98 changes: 95 additions & 3 deletions install-php-extensions
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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*/
}
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions scripts/tests/gd
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b609ff

Please sign in to comment.