在 Mac OS X 中使用 PHP 模块安装 ImageMagick Brew

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11865600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:18:14  来源:igfitidea点击:

ImageMagick Brew installation with PHP Module in Mac OS X

phpmacosimagemagickimagick

提问by Wouter Konecny

I have installed ImageMagick using brew install imagemagick. This all worked fine and I can run any ImageMagick command from the Terminal / Command line.

我已经使用brew install imagemagick. 这一切都很好,我可以从终端/命令行运行任何 ImageMagick 命令。

Now when I try to use the ImageMagick classes in PHP, I get an error Class 'Imagick' not found in .... I guess this is because the ImageMagick module is not loaded.

现在,当我尝试在 PHP 中使用 ImageMagick 类时,出现错误Class 'Imagick' not found in ...。我猜这是因为未加载 ImageMagick 模块。

Could anyone help me to get this thing working in PHP? Thanks!

任何人都可以帮助我让这个东西在 PHP 中工作吗?谢谢!

Additional info:
Mac OS X Version:10.8: Mountain Lion
PHP Version: 5.3.13

附加信息:
Mac OS X 版本:10.8:Mountain Lion
PHP 版本:5.3.13

回答by Daniel Feder

I just did this after a lot of experimenting. For now, this seems to be the way to do it for php 5.3:

我只是在经过大量实验后才这样做的。现在,这似乎是 php 5.3 的方法:

brew tap josegonzalez/php
brew tap homebrew/dupes
brew install php53-imagick

No idea who Jose Gonzalez is but apparently we are in his debt....

不知道何塞冈萨雷斯是谁,但显然我们欠他的债......

回答by Kurt Pfeifle

Your ImageMagick installation is not enough. You also need the Imagick package (possibly called php72-imagickor similar for home brew).

您的 ImageMagick 安装还不够。您还需要 Imagick 包(php72-imagick对于家庭酿造可能称为或类似)。

Imagick doesn't do the work itself, it is a native PHP extension for creating and modifying images using the ImageMagick API.

Imagick 本身不做这项工作,它是一个原生 PHP 扩展,用于使用 ImageMagick API创建和修改图像。

Try to search for the exact name of the package via brew search imagick.

尝试通过 搜索包的确切名称brew search imagick

回答by Mr. 14

I'm using Yosemite. For me, the solution is a combination of the answer and comment already listed here.

我正在使用优胜美地。对我来说,解决方案是这里已经列出的答案和评论的组合。

brew install imagemagick
brew install php55-imagick

Edit /etc/php.ini to include imagick

编辑 /etc/php.ini 以包含 imagick

extension=/usr/local/Cellar/php55-imagick/{version of php55-imagick}/imagick.so

Example:

例子:

extension = /usr/local/Cellar/php55-imagick/3.1.2_1/imagick.so

回答by anytimecoder

php72-imagickis now deprecated as imagick is part of php binary itself. Use peclto install imagick e.g.:

php72-imagick现在已弃用,因为 imagick 是 php 二进制文件本身的一部分。使用pecl安装imagick例如:

brew install php
brew install imagemagick
brew install pkg-config
pecl install imagick

回答by Frank Hag

I had the same issue. These are the steps that worked for me if you are using php 5.6

我遇到过同样的问题。如果您使用的是 php 5.6,这些是对我有用的步骤

  1. brew install php56-imagick
  2. brew install imagemagick
  3. find /usr/local/Cellar -name "imagick.so"
    copy the path from the output of this command into your php.ini file
    e.g. extension=/usr/local/Cellar/php56-imagick/3.3.0_2/imagick.sosave your file. Now to double check that the imagemagick class exists type
  4. php -r "print(class_exists('imagick'));"
  1. brew install php56-imagick
  2. brew install imagemagick
  3. find /usr/local/Cellar -name "imagick.so"
    将此命令的输出路径复制到您的 php.ini 文件中,
    例如extension=/usr/local/Cellar/php56-imagick/3.3.0_2/imagick.so保存您的文件。现在仔细检查 imagemagick 类是否存在类型
  4. php -r "print(class_exists('imagick'));"

Brew symlinking wasn't working for me so I had to put the full pathname into the php.ini file to get it to work. Hope this helps

Brew 符号链接对我不起作用,所以我必须将完整路径名放入 php.ini 文件中才能使其工作。希望这可以帮助

回答by Reza Babaei

this one worked for me:

这个对我有用:

brew install imagemagick       # If it's not already installed
mkdir /usr/local/lib/php/pecl  # On my system this dir didn't exist and this caused pecl install to fail
pecl install imagick

here

这里

回答by diazwatson

Try:

尝试:

brew install homebrew/php/php53-imagick

回答by Grzegorz Mi?kiewicz

I've looking for correct way to install imagick on Mojavie and found solution that fully worked.

我一直在寻找在 Mojavie 上安装 imagick 的正确方法,并找到了完全有效的解决方案。

  1. brew install imagemagick@6
  2. brew install [email protected]
  3. Install headers (Xcode-select --install)
  4. Download imagick source code from: https://pecl.php.net/package/imagick
  5. Open terminal and enter unzipped folder imagick-3.4.3/imagick-3.4.3 (in my case)
  6. Run command phpize
  7. ./configure
  8. make
  1. brew 安装 imagemagick@6
  2. 酿造安装 [email protected]
  3. 安装头文件 (Xcode-select --install)
  4. 从以下位置下载 imagick 源代码:https://pecl.php.net/package/imagick
  5. 打开终端并输入解压缩文件夹 imagick-3.4.3/imagick-3.4.3(在我的情况下)
  6. 运行命令 phpize
  7. 。/配置
  8. 制作

And now if error occurs like MagicWand not found, edit file Makefile and look for CPPFLAGS = -I/usr/local/opt/imagemagick@6/include/. Inspect if in include folder there is no other folder. In my case it should be like this: CPPFLAGS = -I/usr/local/opt/imagemagick@6/include/ImageMagick-6

现在如果出现类似 MagicWand not found 的错误,编辑文件 Makefile 并查找 CPPFLAGS = -I/usr/local/opt/imagemagick@6/include/。检查包含文件夹中是否没有其他文件夹。就我而言,它应该是这样的:CPPFLAGS = -I/usr/local/opt/imagemagick@6/include/ImageMagick-6

save and return to terminal and type make (after finished) sudo make install

保存并返回终端并输入 make(完成后) sudo make install

imagick.so is located in imagick-3.4.3/imagick-3.4.3/modules

imagick.so 位于 imagick-3.4.3/imagick-3.4.3/modules

回答by Jamie Ross

Ok after 1 hour at this I have figured it out. The mac is not giving the pecl script permissions to make a PHP directory. To resolve do as follows.

好的,经过 1 小时后,我想通了。mac 没有授予 pecl 脚本权限来创建 PHP 目录。解决方法如下。

brew install imagemagick
Sudo pecl install imagick .  
php --ini | grep "Loaded Configuration File"
Add extension=imagick.so under extensions.

The install will be complete. Then, to test run:

安装将完成。然后,测试运行:

php -r "print(class_exists('imagick'));"

回答by Henry

I had the same error having already installed imagemagickand php71-imagick.

我已经安装了imagemagickphp71-imagick.

brew upgrade imagemagick- did the trick for me.

brew upgrade imagemagick- 对我有用。

You may need sudo:

您可能需要sudo

sudo brew upgrade imagemagick

sudo brew upgrade imagemagick

You may need to restart apache/ php-fpm/ <other webserver>.

您可能需要重新启动apache/ php-fpm/ <other webserver>