Windows上编译PHP+Imagick
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
将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的相关信息。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

The way to update ByBit exchanges varies by platform and device: Mobile: Check for updates and install in the app store. Desktop Client: Check for updates in the Help menu and install automatically. Web page: You need to manually access the official website for updates. Failure to update the exchange can lead to security vulnerabilities, functional limitations, compatibility issues and reduced transaction execution efficiency.

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

Detailed explanation and installation guide for PiNetwork nodes This article will introduce the PiNetwork ecosystem in detail - Pi nodes, a key role in the PiNetwork ecosystem, and provide complete steps for installation and configuration. After the launch of the PiNetwork blockchain test network, Pi nodes have become an important part of many pioneers actively participating in the testing, preparing for the upcoming main network release. If you don’t know PiNetwork yet, please refer to what is Picoin? What is the price for listing? Pi usage, mining and security analysis. What is PiNetwork? The PiNetwork project started in 2019 and owns its exclusive cryptocurrency Pi Coin. The project aims to create a one that everyone can participate

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total
