ImageMagick / ImageMagick

🧙‍♂️ ImageMagick 7
https://imagemagick.org
Other
12k stars 1.35k forks source link

Can't use ImageMagick in PHP with imagick extension #7634

Open crazywhalecc opened 5 days ago

crazywhalecc commented 5 days ago

ImageMagick version

7.1.1-37 Q16-HDRI x64

Operating system

Windows

Operating system, version and so on

10 LTSC

Description

Related issue #7583

I'm building php-src on windows, and it's a C project, I cannot link imagemagick with imagick extension.

When building php, I got the same error:

ImageMagick was build with a 64 channel bit mask and that requires a C++ compiler

Just tried to use MagickWand in C, too.

Steps to Reproduce

Here's how I build imagemagick-windows:

<?php

declare(strict_types=1);

namespace SPC\builder\windows\library;

use SPC\store\FileSystem;

class imagemagick_windows extends WindowsLibraryBase
{
    public const NAME = 'imagemagick-windows';

    protected function build(): void
    {
        // build configure.exe
        cmd()->cd($this->source_dir . '\Configure')
            ->execWithWrapper($this->builder->makeSimpleWrapper('msbuild /t:Rebuild /p:Configuration=Release /p:Platform=x64'), 'configure.sln');

        // configure for multithreaded static build
        cmd()->cd($this->source_dir . '\Configure')
            ->execWithWrapper($this->builder->makeSimpleWrapper('.\configure.exe'), '/x64 /noWizard /noHdri /noOpenCL /deprecated /smt');

        // build ImageMagick
        cmd()->cd($this->source_dir)
            ->execWithWrapper($this->builder->makeSimpleWrapper('msbuild /t:Rebuild /p:Configuration=Release /p:Platform=x64'), 'IM7.Static.x64.sln');

        // copy all libs and pdb
        FileSystem::resetDir(BUILD_LIB_PATH . '\imagemagick');
        cmd()->cd($this->source_dir . '\Artifacts\lib')
            ->exec('xcopy .\*.lib ' . BUILD_LIB_PATH . '\imagemagick /Y')
            ->exec('xcopy .\*.pdb ' . BUILD_LIB_PATH . '\imagemagick /Y');

        // copy headers
        FileSystem::resetDir(BUILD_INCLUDE_PATH . '\MagickCore');
        FileSystem::resetDir(BUILD_INCLUDE_PATH . '\MagickWand');
        cmd()->cd($this->source_dir . '\ImageMagick\MagickCore')->exec('xcopy .\*.h ' . BUILD_INCLUDE_PATH . '\MagickCore /Y');
        cmd()->cd($this->source_dir . '\ImageMagick\MagickWand')->exec('xcopy .\*.h ' . BUILD_INCLUDE_PATH . '\MagickWand /Y');
        cmd()->cd(BUILD_INCLUDE_PATH)
            ->exec('del .\MagickCore\*-private.h')
            ->exec('del .\MagickWand\*-private.h');

        // remove redundant pdb files
        /*
        lib\CORE_RL_aom_.pdb
        lib\CORE_RL_brotli_.pdb
        lib\CORE_RL_croco_.pdb
        lib\CORE_RL_ffi_.pdb
        lib\CORE_RL_highway_.pdb
        lib\CORE_RL_libde265_.pdb
        lib\CORE_RL_pixman_.pdb
        lib\CORE_RL_raqm_.pdb
         */
        cmd()->cd(BUILD_LIB_PATH . '\imagemagick')
            ->exec('del .\CORE_RL_aom_.pdb')
            ->exec('del .\CORE_RL_brotli_.pdb')
            ->exec('del .\CORE_RL_croco_.pdb')
            ->exec('del .\CORE_RL_ffi_.pdb')
            ->exec('del .\CORE_RL_highway_.pdb')
            ->exec('del .\CORE_RL_libde265_.pdb')
            ->exec('del .\CORE_RL_pixman_.pdb')
            ->exec('del .\CORE_RL_raqm_.pdb');
    }
}

And for imagick extension, I did modification here (config.w32):

# Add PHP_IMAGICK_SHARED, /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1

EXTENSION('imagick', 'imagick_class.c imagickdraw_class.c imagickpixel_class.c imagickpixeliterator_class.c imagick_helpers.c imagick_file.c imagick.c imagickkernel_class.c shim_im6_to_im7.c', PHP_IMAGICK_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");

And using static-php-cli to build php.exe statically, got error:

NMAKE : fatal error U1077: “"cl.exe" /D _USRDLL /D PHP7DLLTS_EXPORTS /D PHP_EXPORTS /D LIBZEND_EXPORTS /D TSRM_EXPORTS /D SAPI_EXPORTS /D WINVER=0x0601 /I "C:\spc-build\static-php-cli\buildroot\include" /DH
AVE_MAGICKWAC:\spc-build\static-php-cli\buildroot\include\MagickCore/magick-baseconfig.h(269): fatal error C1189: #error:  ImageMagick was build with a 64 channel bit mask and that requires a C++ compiler (编译源文件 ext\imagick\imagickkernel_class.c)
ND_MAGICKWAND_H=1 /D IM_MAGICKWAND_HEADER_STYLE_SEVEN /D IMAGICK_USE_NEW_HEADER /D _MAGICKMOD_ /D _VISUALC_ /D NeedFunctionPrototypes /D _LIB /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 /nologo /I . /I main /I Zend
 /I TSRM /I ext /D _WINDOWS /D WINDOWS=1 /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /D _USE_MATH_DEFINES /FD /wd4996 /Zc:inline /Zc:__cplusplus /d2FuncCache1 /Zc:wchar_t /MP /LD /MT /Ox /D NDebug /D N
DEBUG /GF /D ZEND_DEBUG=0 /I "C:\spc-build\static-php-cli\buildroot\include" /D FD_SETSIZE=256 /FoC:\spc-build\static-php-cli\source\php-src\x64\Release\ext\imagick\ /FpC:\spc-build\static-php-cli\source\ph
p-src\x64\Release\ext\imagick\ /FRC:\spc-build\static-php-cli\source\php-src\x64\Release\ext\imagick\ /FdC:\spc-build\static-php-cli\source\php-src\x64\Release\ext\imagick\ /c ext\imagick\imagick.c ext\imag
ick\imagick_class.c ext\imagick\imagick_file.c ext\imagick\imagick_helpers.c ext\imagick\imagickdraw_class.c ext\imagick\imagickkernel_class.c ext\imagick\imagickpixel_class.c ext\imagick\imagickpixeliterator_class.c ext\imagick\shim_im6_to_im7.c”: 返回代码“0x2”
Stop.

Images

There is no image.

It's unrealistic to give you a full understanding of static-php-cli project, but if you have an idea for solving this problem or what caused it, I'd love to know. Thanks.

dlemstra commented 1 day ago

You will either need switch to a C++ compiler or rebuild ImageMagick with 64 bit channel mask support yourself.

crazywhalecc commented 1 day ago

@dlemstra Thank you for your help. And I'm a newbie in Windows build, how can I achieve it?

dlemstra commented 3 hours ago

It looks like you are using our build tooling in your script. We don't have support for disabling C++ builds and we will not be going to add an option for that.