Home php教程 php手册 Windows上编译PHP+Imagick

Windows上编译PHP+Imagick

Jun 14, 2016 am 12:02 AM
imagick php windows code Open source programming programming language compile software development

PHP通过Imagick扩展来实现对图片的处理,Imagick扩展是基于ImageMagick的,但Imagick扩展不是PHP自带的,如果用户想使用它,要么寻找Windows的Binary文件,要么自己编译一个。如果在Linux上,这些都不是问题。但Windows上相关的资料少之又少。下面简单介绍一下本人的编译过程。

准备过程:

1. 下载PHP源代码和编译工具
    PHP的源代码可以从www.php.net上下载,具体的下载地址可以到download页面(http://www.php.net/downloads.php)上寻找。

  然后到documentation页面(http://www.php.net/docs.php)上寻找编译过程的帮助,具体页面是:http://www.php.net/manual/zh/install.windows.building.php。

  可以从这个页面上下载相关的编译工具:win32build和bindlib_w32,并将他们解压缩到源代码放在同级的目录中,具体目录结构如下: 

+--BuildRootDir
|  |
|  +--bindlib_w32
|  |  |
|  |  +--arpa
|  |  |
|  |  +--conf
|  |  |
|  |  +--...
|  |
|  +--php-5.x.x
|  |  |
|  |  +--build
|  |  |
|  |  +--...
|  |  |
|  |  +--win32
|  |  |
|  |  +--...
|  |
|  +--win32build
|  |  |
|  |  +--bin
|  |  |
|  |  +--include
|  |  |
|  |  +--lib
Copy after login

将win32build\bin目录添加到系统环境变量Path中,这一步也可以在编译的时候指定。此外,需要在C盘建一个目录C:\usr\local\bin,将win32build\bin\目录下的bison.simple拷贝到此目录中。

完成上述工作后,编译resolv.lib。此文件的VC工程文件位于:bindlib_w32下,可以使用VC打开工程文件然后编译即可,将编译产生的resolv.lib拷贝到win32build\lib目录下(如果此文件已存在,覆盖之)。

至此,PHP的编译准备工作已完成。

2. 下载ImageMagick安装包并安装

    到ImageMagick主页(http://www.imagemagick.org/script/index.php)上下载Windows的Binary文件(http://www.imagemagick.org/script/binary-releases.php?ImageMagick=ir9ijldaeppff0fudjv4kmfcj0#windows),请选择dll版本,因为只有dll版中有development相关的文件。安装dll版本,安装过程中一定要勾选:install development headers and libraries for C and C++和Add application directory into your system path两个选项。

3. 下载Imagick源代码

 到ImageMagick的Program interface页面上(http://www.imagemagick.org/script/api.php)寻找PHP接口Imagick。然后下载(http://pecl.php.net/package/imagick)并解压到php源代码目录下的ext目录中(BuildRootDir/php-5.x.x/ext/imagick)。打开imagick目录下的config.w32文件,替换imagick_read.c为imagick_file.c。此处很可能是imagick的一个Bug。切记。

4. 配置Windows

   如果你的Windows系统不是英文版或者默认打开文件的编码不是English(US),编译过程很可能会fail。因此需要对Windows系统的配置稍作改动,具体为:打开控制面板,选择区域与语言,找到非Unicode程序的语言项,然后配置默认使用语言为英语(美国)/English(US)。

经过以上4步之后,终于可以进行编译了。

编译过程:

使用VC的Command Prombt进入字符界面(cmd界面),然后cd到php的目录,检查一下path,看系统path中是否包括win32build\bin目录,如果没有包含进来,需要执行:set path=BuildRootDir\win32build\bin;%path%.

然后在php的源代码目录下执行buildconf.bat文件用于产生configure.js文件。然后系统提示键入"configure --help”.此时可以直接键入configure --enable-snapshot-build --disable-zip --disable-zlib --with-imagick=shared

注意以下最后生成的报告中是否包含imagick shared这样的一行。如果有,表示configure已经成功。可以键入nmake snap进行编译了。建议使用nmake snap >build.log将编译输出重定向到一个文件中。因为编译过程太长,使用日志文件方便日后检查。

编译完成之后会有一个Release_TS目录,下面会有php-5.x.x(5.x.x是你的php版本号)和3个zip文件。

编译的最终结果就位于php-5.x.x目录中。可以将它Copy到你需要的位置使用它。

测试编译结果:

以下是phpinfo()返回的关于imagick的相关信息。

Windows上编译PHP+Imagick

  

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP's Current Status: A Look at Web Development Trends PHP's Current Status: A Look at Web Development Trends Apr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP: The Foundation of Many Websites PHP: The Foundation of Many Websites Apr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Python: Games, GUIs, and More Python: Games, GUIs, and More Apr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

Oracle database uninstall tutorial Oracle database uninstall tutorial Apr 11, 2025 pm 06:24 PM

To uninstall an Oracle database: stop the Oracle service, remove the Oracle instance, delete the Oracle home directory, clear the registry key (Windows only), and delete the environment variables (Windows only). Please back up the data before uninstalling.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

See all articles