From 2ed2214b2a66a7a0fab6eb323f9e6ab03ab2e102 Mon Sep 17 00:00:00 2001 From: michalananapps <132371766+michalananapps@users.noreply.github.com> Date: Sat, 30 Nov 2024 10:03:03 +0100 Subject: [PATCH 1/4] fix: Fix compatibility with php 8.4 and newer ImageMagick library versions --- .github/workflows/main.yml | 26 ++++---------------------- .github/workflows/windows.yml | 5 +++-- imagick.c | 6 +++--- imagick_helpers.c | 26 +++++++++++--------------- php_imagick_macros.h | 19 +++++++++++++++++++ util/calculate_cflags.php | 5 +++-- 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ee2dfecc..914642a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,11 +14,10 @@ jobs: fail-fast: false matrix: os: [ ubuntu-latest ] - # php: [ 5.4 ] php: [ 8.3 ] imagemagick: [ - 7.1.0-13, - 6.8.7-0, + 7.1.1-41, + 6.9.2-0, ] runs-on: ${{ matrix.os }} @@ -80,7 +79,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-latest ] - php: [5.4, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5] + php: [8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5] imagemagick: [ 7.1.0-13, 7.0.10-27, @@ -89,26 +88,9 @@ jobs: git7, 6.9.2-0, 6.8.7-0, - 6.7.8-0, - git6 + 6.7.8-0 ] exclude: - - php: 5.4 - imagemagick: 6.8.7-0 - - php: 7.4 - imagemagick: git6 - - php: 7.3 - imagemagick: git6 - - php: 7.2 - imagemagick: git6 - - php: 7.1 - imagemagick: git6 - - php: 7.0 - imagemagick: git6 - - php: 5.6 - imagemagick: git6 - - php: 5.5 - imagemagick: git6 - php: 7.4 imagemagick: git7 - php: 7.3 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d2ee1a29..dc3a6cc6 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -16,14 +16,15 @@ jobs: uses: actions/checkout@v4 - name: Setup PHP id: setup-php - uses: cmb69/setup-php-sdk@v0.7 + uses: php/setup-php-sdk@v0.10 with: version: ${{matrix.version}} arch: ${{matrix.arch}} ts: ${{matrix.ts}} + cache: true - name: Download deps run: | - curl -LO https://windows.php.net/downloads/pecl/deps/ImageMagick-7.1.0-18-vc15-${{matrix.arch}}.zip + curl -LO https://downloads.php.net/~windows/pecl/deps/ImageMagick-7.1.0-18-vc15-${{matrix.arch}}.zip 7z x ImageMagick-7.1.0-18-vc15-${{matrix.arch}}.zip -o..\deps - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1 diff --git a/imagick.c b/imagick.c index 1b765389..ebab7ae7 100644 --- a/imagick.c +++ b/imagick.c @@ -610,7 +610,7 @@ static zval *php_imagick_read_property(zend_object *object, zend_string *member, if (format) { retval = rv; ZVAL_STRING(retval, format); - php_strtolower(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + zend_str_tolower(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); IMAGICK_FREE_MAGICK_MEMORY(format); } else { retval = rv; @@ -683,7 +683,7 @@ static zval *php_imagick_read_property(zval *object, zval *member, int type, voi if (format) { retval = rv; ZVAL_STRING(retval, format); - php_strtolower(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + zend_str_tolower(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); IMAGICK_FREE_MAGICK_MEMORY(format); } else { retval = rv; @@ -766,7 +766,7 @@ static zval *php_imagick_read_property(zval *object, zval *member, int type, con if (format) { ZVAL_STRING(retval, format, 1); - php_strtolower(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + zend_str_tolower(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); IMAGICK_FREE_MAGICK_MEMORY(format); } else { ZVAL_STRING(retval, "", 1); diff --git a/imagick_helpers.c b/imagick_helpers.c index e544cb1c..736836fb 100644 --- a/imagick_helpers.c +++ b/imagick_helpers.c @@ -1197,6 +1197,11 @@ void php_imagick_initialize_constants(TSRMLS_D) #if MagickLibVersion >= 0x707 IMAGICK_REGISTER_CONST_LONG("FILTER_CUBIC_SPLINE", CubicSplineFilter); #endif +#if MAGICK_LIB_VERSION_GTE(7, 1, 1, 40) + IMAGICK_REGISTER_CONST_LONG("FILTER_MAGIC_KERNEL_SHARP_2013", MagicKernelSharp2013Filter); + IMAGICK_REGISTER_CONST_LONG("FILTER_MAGIC_KERNEL_SHARP_2021", MagicKernelSharp2021Filter); +#endif + IMAGICK_REGISTER_CONST_LONG("IMGTYPE_UNDEFINED", UndefinedType); IMAGICK_REGISTER_CONST_LONG("IMGTYPE_BILEVEL", BilevelType); IMAGICK_REGISTER_CONST_LONG("IMGTYPE_GRAYSCALE", GrayscaleType); @@ -1279,9 +1284,7 @@ void php_imagick_initialize_constants(TSRMLS_D) IMAGICK_REGISTER_CONST_LONG("COMPRESSION_WEBP", WebPCompression); #endif -#if MagickLibVersion >= 0x711 - // Technically >= 7.1.0-13 but we still don't have a mechanism for - // detecting patch versions. +#if MAGICK_LIB_VERSION_GTE(7, 1, 0, 13) IMAGICK_REGISTER_CONST_LONG("COMPRESSION_BC5", BC5Compression); IMAGICK_REGISTER_CONST_LONG("COMPRESSION_BC7", BC7Compression); #endif @@ -1291,8 +1294,7 @@ void php_imagick_initialize_constants(TSRMLS_D) IMAGICK_REGISTER_CONST_LONG("COMPRESSION_DWAB", DWABCompression); #endif -#if MagickLibVersion >= 0x712 - // actually 7.1.1-16, but still can't test patch versions +#if MAGICK_LIB_VERSION_GTE(7, 1, 1, 16) IMAGICK_REGISTER_CONST_LONG("COMPRESSION_LERC", LERCCompression); #endif @@ -1554,9 +1556,7 @@ void php_imagick_initialize_constants(TSRMLS_D) IMAGICK_REGISTER_CONST_LONG("COLORSPACE_PROPHOTO", ProPhotoColorspace); #endif -#if MagickLibVersion >= 0x712 - // Technically >= 7.1.1-9 but we still don't have a mechanism for - // detecting patch versions. +#if MAGICK_LIB_VERSION_GTE(7, 1, 1, 9) IMAGICK_REGISTER_CONST_LONG("COLORSPACE_OKLAB", OklabColorspace); IMAGICK_REGISTER_CONST_LONG("COLORSPACE_OKLCH", OklchColorspace); #endif @@ -1823,9 +1823,7 @@ void php_imagick_initialize_constants(TSRMLS_D) IMAGICK_REGISTER_CONST_LONG("ALPHACHANNEL_DISSOCIATE", DisassociateAlphaChannel); #endif -#if MagickLibVersion >= 0x712 - // Technically >= 7.1.1-26 but we still don't have a mechanism for - // detecting patch versions. +#if MAGICK_LIB_VERSION_GTE(7, 1, 1, 26) IMAGICK_REGISTER_CONST_LONG("ALPHACHANNEL_OFF_IF_OPAQUE", OffIfOpaqueAlphaChannel); #endif @@ -1969,10 +1967,8 @@ IMAGICK_REGISTER_CONST_LONG("KERNEL_BINOMIAL", BinomialKernel); IMAGICK_REGISTER_CONST_LONG("DIRECTION_LEFT_TO_RIGHT", LeftToRightDirection); IMAGICK_REGISTER_CONST_LONG("DIRECTION_RIGHT_TO_LEFT", RightToLeftDirection); -#if MagickLibVersion >= 0x712 - // Technically >= 7.1.1-14 but we still don't have a mechanism for - // detecting patch versions. - IMAGICK_REGISTER_CONST_LONG("DIRECTION_TOP_TO_BOTTOM", TopToBottomDirection); +#if MAGICK_LIB_VERSION_GTE(7, 1, 1, 14) + IMAGICK_REGISTER_CONST_LONG("DIRECTION_TOP_TO_BOTTOM", TopToBottomDirection); #endif // The kernel is scaled directly using given scaling factor without change. diff --git a/php_imagick_macros.h b/php_imagick_macros.h index c63b62a8..0c1e82a7 100644 --- a/php_imagick_macros.h +++ b/php_imagick_macros.h @@ -21,6 +21,25 @@ #ifndef PHP_IMAGICK_MACROS_H # define PHP_IMAGICK_MACROS_H +#define EXTRACT_BUILD_NUMBER(str) ({ \ + int build = 0; \ + const char *s = str; \ + while (*s && !isdigit(*s)) s++; \ + if (*s) build = atoi(s); \ + build; \ +}) + +#define MAGICK_LIB_VERSION_MAJOR ((MagickLibVersion >> 8) & 0xFF) +#define MAGICK_LIB_VERSION_MINOR ((MagickLibVersion >> 4) & 0xF) +#define MAGICK_LIB_VERSION_PATCH (MagickLibVersion & 0xF) +#define MAGICK_LIB_VERSION_BUILD EXTRACT_BUILD_NUMBER(MagickLibAddendum) + +#define MAGICK_LIB_VERSION_GTE(major, minor, patch, build) \ + ((VERSION_MAJOR > (major)) || \ + (VERSION_MAJOR == (major) && VERSION_MINOR > (minor)) || \ + (VERSION_MAJOR == (major) && VERSION_MINOR == (minor) && VERSION_PATCH > (patch)) || \ + (VERSION_MAJOR == (major) && VERSION_MINOR == (minor) && VERSION_PATCH == (patch) && VERSION_BUILD >= (build))) + #define IMAGICK_FREE_MAGICK_MEMORY(value) \ do { \ if (value) { \ diff --git a/util/calculate_cflags.php b/util/calculate_cflags.php index 61263a9b..9a6c23c0 100644 --- a/util/calculate_cflags.php +++ b/util/calculate_cflags.php @@ -58,8 +58,7 @@ if ($PHP_VERSION == "5.4" || $PHP_VERSION == "5.5") { $CFLAGS = array("-Wno-deprecated-declarations"); -} -else if ($PHP_VERSION == "5.6") { +} elseif ($PHP_VERSION == "5.6") { $CFLAGS = array( "-Wno-deprecated-declarations", "-Wdeclaration-after-statement", @@ -67,6 +66,8 @@ "-Wall", "-Wimplicit-function-declaration" ); +} elseif ($PHP_VERSION == "8.4") { + $CFLAGS[] = "-Wno-missing-field-initializers"; } $result = implode(" ", $CFLAGS); From 620730e4ebe7f8335c24a646448855396b863f62 Mon Sep 17 00:00:00 2001 From: michalananapps <132371766+michalananapps@users.noreply.github.com> Date: Sat, 30 Nov 2024 10:21:02 +0100 Subject: [PATCH 2/4] fix: Fix compatibility with php 8.4 and newer ImageMagick library versions --- .github/workflows/windows.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index dc3a6cc6..81fbb36d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -7,10 +7,18 @@ jobs: shell: cmd strategy: matrix: - version: ["7.4", "8.0"] - arch: [x64] - ts: [ts] - runs-on: windows-2019 + os: [windows-2019, windows-2022] + version: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] + arch: [x64] + ts: [ts] + exclude: + - {os: windows-2019, version: "8.4"} + - {os: windows-2019, version: "8.3"} + - {os: windows-2019, version: "8.2"} + - {os: windows-2019, version: "8.1"} + - {os: windows-2019, version: "8.0"} + - {os: windows-2022, version: "7.4"} + runs-on: ${{matrix.os}} steps: - name: Checkout imagick uses: actions/checkout@v4 From 300f9faec71267ac0310aff0458f9aa54ced6a43 Mon Sep 17 00:00:00 2001 From: michalananapps <132371766+michalananapps@users.noreply.github.com> Date: Sat, 30 Nov 2024 10:51:10 +0100 Subject: [PATCH 3/4] add git6 --- .github/workflows/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 914642a9..70f80117 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,14 +81,15 @@ jobs: os: [ ubuntu-latest ] php: [8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5] imagemagick: [ - 7.1.0-13, - 7.0.10-27, + 7.1.1-41, + 7.0.11-14, 7.0.8-4, 7.0.1-0, git7, 6.9.2-0, 6.8.7-0, - 6.7.8-0 + 6.7.8-0, + git6, ] exclude: - php: 7.4 From cd0bc8f4269ee3845b2cc216f5555dc2a676712b Mon Sep 17 00:00:00 2001 From: michalananapps <132371766+michalananapps@users.noreply.github.com> Date: Sat, 30 Nov 2024 11:32:02 +0100 Subject: [PATCH 4/4] exclude 7.1.1-41 on php5.5 --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70f80117..d0a17006 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -106,6 +106,8 @@ jobs: imagemagick: git7 - php: 5.5 imagemagick: git7 + - php: 5.5 + imagemagick: 7.1.1-41 runs-on: ${{ matrix.os }} steps: