Imagick php 窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18375092/
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 17:25:43  来源:igfitidea点击:

Imagick php windows

phpimagick

提问by ABS

I am trying to use iMagick in Symfony2.

我正在尝试在 Symfony2 中使用 iMagick。

I am using PHP 5.4.16 and all i have done :

我正在使用 PHP 5.4.16 和我所做的一切:

1-Copy php_imagick_nts.dll from php5-4 directory from the extracted http://valokuva.org/~mikko/imagick-php54-php53.tgzto php/ext .

1-将 php_imagick_nts.dll 从 php5-4 目录中提取的http://valokuva.org/~mikko/imagick-php54-php53.tgz复制到 php/ext 。

2-Rename it to php_imagick.dll and add the “extension=php_imagick.dll” to php.ini

2-将其重命名为 php_imagick.dll 并将“extension=php_imagick.dll”添加到 php.ini

3-Create a page like this :

3-创建一个这样的页面:

<?php 
    $a = new Imagick();
?>

but i receive this :

但我收到了这个:

Fatal error: Class ‘Imagick' not found in C:\xampp\htdocs\info.php

When I tried to use this in a symfony controller, the error occur again:

当我尝试在 symfony 控制器中使用它时,错误再次发生:

FatalErrorException: Error: Class 'Imagick' not found

Unfortunately the details about imagick extension not appear in output of "phpinfo()"

不幸的是,有关 imagick 扩展的详细信息没有出现在“phpinfo()”的输出中

Is this version is incompatible with PHP 5.4.16 ?! If yes,what version i must use? Where? Thank for any help...

此版本是否与 PHP 5.4.16 不兼容?!如果是,我必须使用什么版本?在哪里?感谢您的帮助...

回答by fmstoun

I spent many hours trying to make Imagick work, finally I got it.

我花了很多时间试图让 Imagick 工作,最后我明白了。

My installation instructions

我的安装说明

  1. Install WAMP 32bit (even if you running 64bit system you must use 32bit version of WAMP)
  2. Install ImageMagick to C:/imagemagick, use this file: https://www.dropbox.com/s/i2mhrhd7sp0ilzk/ImageMagick-6.8.0-3-Q16-windows-dll.exe
  3. Put DLL with Imagick into extension folder of PHP, e.g. D:\wamp32\bin\php\php5.4.16\ext, I used this file: https://www.dropbox.com/s/ayankf850l08rm2/php_imagick.dll
  4. In php.ini put line "SetEnv MAGICK_HOME C:/imagemagick" without quotes
  5. Better restart PC
  1. 安装 WAMP 32bit(即使你运行的是 64bit 系统你也必须使用 32bit 版本的 WAMP)
  2. 安装ImageMagick到C:/imagemagick,使用这个文件:https: //www.dropbox.com/s/i2mhrhd7sp0ilzk/ImageMagick-6.8.0-3-Q16-windows-dll.exe
  3. 将带有Imagick的DLL放入PHP的扩展文件夹中,例如D:\wamp32\bin\php\php5.4.16\ext,我使用了这个文件:https://www.dropbox.com/s/ayankf850l08rm2/php_imagick.dll
  4. 在 php.ini 中放置“SetEnv MAGICK_HOME C:/imagemagick”行,不带引号
  5. 最好重启电脑

I use Wamp 2.4, PHP 5.4.16, Apache 2.4.4, ImageMagick 6.8.0-3 2012-10-24 Q16, Imagick 3.1.0RC2 - all 32bit, OS Win8 64bit

我使用 Wamp 2.4、PHP 5.4.16、Apache 2.4.4、ImageMagick 6.8.0-3 2012-10-24 Q16、Imagick 3.1.0RC2 - 全部 32 位,操作系统 Win8 64 位

Now it should work and you should see Imagick extension loaded in phpinfo.

现在它应该可以工作了,您应该会看到 phpinfo 中加载了 Imagick 扩展。

I tried a lot of versions of ImageMagick, but newer versions didn't work, 6.8.0-3-Q16-windows-dll works fine.

我尝试了很多版本的 ImageMagick,但较新的版本不起作用,6.8.0-3-Q16-windows-dll 工作正常。

Symfony2

Symfony2

In Symfony2 use Imagick like this:

在 Symfony2 中像这样使用 Imagick:

$im = new \Imagick('image.jpg');

回答by nkmol

After trying many solutions, none seemed to work.

在尝试了许多解决方案之后,似乎都没有奏效。

I managed to install it on Windows 10 64-bit, Apache 2.4 and PHP 5.6, but I think it should work for all versions.

我设法将它安装在 Windows 10 64 位、Apache 2.4 和 PHP 5.6 上,但我认为它应该适用于所有版本。

Hopefully you will have no problem installing Imagick for PHP.

希望您在为 PHP 安装 Imagick 时没有问题。



Step 1) Gather information

步骤 1) 收集信息

First of all you should gather some information of your PHP environment.

首先,您应该收集一些有关您的 PHP 环境的信息。

You can easily see your PHP information with the function phpinfo()

您可以使用该功能轻松查看您的PHP信息 phpinfo()

The information you need:

您需要的信息:

  • Architecture:x86(32-bit) or x64(64-bit)
  • PHP-version:you can find this in the header of the phpinfo()output.
  • PHP Extension Build:This string contains 2 important parts:
    • NTS or TS
    • VCx (like VC11)
  • Loaded Configuration File:the path to your used php.inifile.
  • 架构:x86(32 位)或 x64(64 位)
  • PHP-version:您可以在phpinfo()输出的标题中找到它。
  • PHP 扩展构建:此字符串包含 2 个重要部分:
    • NTS 或 TS
    • VCx(如 VC11)
  • 加载的配置文件:您使用的php.ini文件的路径。

Step 2) Download Binary

步骤 2) 下载二进制文件

You can download the binary from the official site of ImageMagick. I recommend you to read the small introduction under the "Windows Binary Release" to be certain which "bits-per-pixel" to choose from(8 or 16). Downloading the latest version should be just fine.

您可以从 ImageMagick 的官方网站下载二进制文件。我建议您阅读“Windows 二进制版本”下的小介绍,以确定可以选择哪个“每像素位数”(8 或 16)。下载最新版本应该没问题。

Make sure this binary is the same architecture as your PHP architecture that you have gathered in step 1.

确保此二进制文件与您在步骤 1 中收集的 PHP 架构相同。

Step 3) Install Binary

步骤 3) 安装二进制文件

Install the binary to your phpx.x.xx\binfile. For example: C:\wamp64\bin\php\php5.6.16\bin. (This can be any folder, but for the convenience I put in here)

将二进制phpx.x.xx\bin文件安装到您的文件中。例如:C:\wamp64\bin\php\php5.6.16\bin。(这可以是任何文件夹,但为了方便我放在这里)

Make sure "Add application directory to your system path" is checked. Should be checked by default though.

确保选中“将应用程序目录添加到系统路径”。但是应该默认选中。

Step 4) Download PHP extension

步骤 4) 下载 PHP 扩展

The DLLPHP extension is available through the windows pecl php site

DLLPHP扩展,可通过窗户PECL PHP网站

Again, you can just click the latest version.

同样,您只需单击最新版本即可。

Next of, choose the right version based on the gathered information.
For example: php_imagick-3.4.1-5.6-nts-vc11-x64.zip

接下来,根据收集到的信息选择正确的版本。
例如:php_imagick-3.4.1-5.6-nts-vc11-x64.zip

This can be stripped into components:

这可以分解为组件:

  • php_imagick-3.4.1- This is the php imagick extension with the version. This is not important.
  • 5.6- This is your PHP version and should be equal to the PHP-version you are using, which you have determed in step 1.
  • NTS- This should be equal to the information of your PHP Extension Build that you have gathered in step 1.
  • VC11- This should also be equal to the information of your PHP Extension Build that you have gathered in step 1.
  • x64- This the architecture of the extension and should be equal to your PHP architecture that you have gathered in step 1.
  • php_imagick-3.4.1- 这是带有该版本的 php imagick 扩展。这并不重要。
  • 5.6- 这是您的 PHP 版本,应该与您在步骤 1 中确定的您正在使用的 PHP 版本相同。
  • NTS- 这应该等于您在步骤 1 中收集的 PHP 扩展构建的信息。
  • VC11- 这也应该等于您在步骤 1 中收集的 PHP 扩展构建的信息。
  • x64- 这是扩展的架构,应该与您在步骤 1 中收集的 PHP 架构相同。

Step 5) Extract PHP Extension

步骤 5) 提取 PHP 扩展

After you have downloaded the file, you should open the .zipfile and look for a file named: php_imagick.dll. Extract this file to phpx.x.xx\ext.

下载文件后,您应该打开该.zip文件并查找名为:php_imagick.dll的文件。将此文件解压缩到phpx.x.xx\ext.

Make sure the .dllfile is fully accessable by you. Sometimes you need to explicity unblock the file.

确保.dll您可以完全访问该文件。有时您需要明确取消阻止文件。

Unblock file

取消阻止文件

Step 6) Activate PHP extension

步骤 6) 激活 PHP 扩展

To activate the extension in PHP, you should state in your php.inifile that you want to use this extension. You have gathered the path to your usedphp.inifile in step 1.

要在 PHP 中激活扩展,您应该在php.ini文件中声明要使用此扩展。您已在步骤 1 中收集了使用php.ini文件的路径。

Add the line extension=php_imagick.dllto your php.ini

将该行添加extension=php_imagick.dll到您的php.ini

PHP.ini Imagick line

PHP.ini Imagick 行

Step 7) Restart your PC

步骤 7) 重新启动您的 PC

Just to make sure, restart your PC so all Environment Paths will be correctly loaded.

只是为了确保,重新启动您的 PC,以便Environment Path正确加载所有s。



This should install Imagickcorrectly with the latest versions and the right architecture. Imagickshould also be listed in phpinfo()with the appropriate "ImageMagick supported formats" (Just make sure it is not empty).

这应该Imagick使用最新版本和正确的架构正确安装。 Imagick还应phpinfo()与适当的“ImageMagick 支持的格式”一起列出(只需确保它不为空)。

回答by MackieeE

I'm quite sure this is to do with nothaving the module loaded correctly or the .dll being placed in a improper location.

我很确定这与没有正确加载模块或 .dll 放置在不正确的位置有关。

You can use PHP's internal function extension_loaded()to check prior to using the class,

在使用该类之前,您可以使用 PHP 的内部函数extension_loaded()进行检查,

<?php
  /**
   * 
  **/
  if (!extension_loaded('Imagick')) {
        //Load some error.
  }
?>

That's a method you can check if the module is even being reconsigned by PHP at all. PHP also provides a function to view your current extensions get_loaded_extensions():

这是一种您可以检查模块是否甚至被 PHP 重新委托的方法。PHP 还提供了一个函数来查看您当前的扩展get_loaded_extensions()

<?php 
   /**
    *   Get an Array of current
    *   PHP extensions for debugging
   **/
   print_r( get_loaded_extensions() );
?>

Make sure you do:

确保你这样做:

  • Check your correctextension library folder location within your phpinfo()
  • Perform a hard restartof your xmapp/wamp server.
  • If you're on PHP 5.4 or upwards (Like yourself!), see site below for the updated binaries
  • 检查您的正确扩展库文件夹位置phpinfo()
  • 对您的 xmapp/wamp 服务器执行硬重启
  • 如果您使用的是 PHP 5.4 或更高版本(就像您自己一样!),请参阅下面的站点以获取更新的二进制文件

After researching too, Imagick does seem to have trouble with PHP 5.3 or upwards; Download new DLL's from this site below (Unofficial):

经过研究,Imagick 在 PHP 5.3 或更高版本上似乎确实有问题;从以下站点下载新的 DLL(非官方):

http://www.peewit.fr/imagick/

http://www.peewit.fr/imagick/

Also found other StackOverFlow Articles that have the same problem:

还发现了其他有同样问题的 StackOverFlow 文章:

Stackoverflow: Trying to get imagick running on PHP 5.4.3 at Windows x64

Stackoverflow尝试在 Windows x64 上的 PHP 5.4.3 上运行 imagick

Alternativelyyou're able to use the GD extensionto more or less accomplish some of the same functions you require. I do believe GDis a more widely supported module/extension in more recent versions of PHP.

或者,您可以使用GD 扩展或多或少地完成一些您需要的相同功能。我确实相信GD是较新版本的 PHP 中更广泛支持的模块/扩展。

回答by learner

I use :Wamp 2.4, PHP 5.4.16, Apache 2.4.4, ImageMagick 6.8.0-3 2012-10-24 Q16, Imagick 3.1.0RC2 - all 32bit, OS Win7 32bit

我使用:Wamp 2.4、PHP 5.4.16、Apache 2.4.4、ImageMagick 6.8.0-3 2012-10-24 Q16、Imagick 3.1.0RC2 - 全部 32 位,操作系统 Win7 32 位

Instructions given by fmstoun worked for me perfectly. Since I spent a lot of hours trying to make the dll work, I wanted to add on to steps given by fmstoun.

fmstoun 给出的说明对我来说非常有效。由于我花了很多时间试图使 dll 工作,因此我想添加 fmstoun 给出的步骤。

  • Do restart your PC.
  • Use the full path to the image, for example:
  • 一定要重启你的电脑。
  • 使用图像的完整路径,例如:
$image = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/test.jpg');
  • Make sure your system environment has 1 single entry for : C:/imagemagick and no more environment variables for imagemagick. If any previous installations have the path, then remove those paths and restart your PC
  • Make sure
    http : / / localhost/
    of wamp shows 'imagick' as loaded extension
  • If extension is loaded properly, it has to show up in phpinfo() also as:
  • imagick module  | enabled
  • ImageMagick version|ImageMagick 6.8.0-3 2012-10-24 Q16 
    and some more information about imagemagick.
  • 确保您的系统环境有 1 个用于 :C:/imagemagick 的条目,并且没有更多用于 imagemagick 的环境变量。如果任何以前的安装有路径,则删除这些路径并重新启动您的 PC
  • 确保
    http : / / localhost/
    wamp 显示“imagick”作为加载的扩展
  • 如果扩展正确加载,它也必须显示在 phpinfo() 中:
  • imagick module  | enabled
  • ImageMagick version|ImageMagick 6.8.0-3 2012-10-24 Q16 
    以及更多关于 imagemagick 的信息。

Considering the date of this post, the latest version of imagemagick provided on the official site is: ImageMagick-6.8.8-1-Q16-x86-dll.exe which fails to load the extension (as seen in apache error logs after a restart). Hence use the version mentioned by fmstoun.

考虑到这篇文章的日期,官方网站上提供的最新版本的imagemagick是:ImageMagick-6.8.8-1-Q16-x86-dll.exe 无法加载扩展(如重启后apache错误日志中所示) )。因此使用 fmstoun 提到的版本。

Hope this answer saves couple of hours of effort and saves time required to go through around 15 SO questions on same topic and also different forums.

希望这个答案可以节省几个小时的精力,并节省在同一主题和不同论坛上解决大约 15 个 SO 问题所需的时间。

回答by Chiu Chun Sun

UPDATE for those 2019 also using WAMP, a much more simplier method of ImageMagick are as follows:

对于那些 2019 年也使用 WAMP 的更新,ImageMagick 的一种更简单的方法如下:

  1. Go to https://mlocati.github.io/articles/php-windows-imagick.html.
  2. Grab a copy of the .dll extension file of your appropriate setup, choose a "Threads Safe" version.
  3. Grab the corresponding ImageMagick using the link on the same row and install it.
  4. Copy only the .dll file to the extensions folder of your install of WAMP, usually C:\wamp\bin\apache2.4\ext\
  5. Restart apache.
  1. 转到https://mlocati.github.io/articles/php-windows-imagick.html
  2. 获取适当设置的 .dll 扩展文件的副本,选择“线程安全”版本。
  3. 使用同一行上的链接获取相应的 ImageMagick 并安装它。
  4. 仅将 .dll 文件复制到 WAMP 安装的扩展文件夹中,通常为 C:\wamp\bin\apache2.4\ext\
  5. 重启阿帕奇。

Hope this helps.

希望这可以帮助。

回答by lucasgabmoreno

Sorry for my bad english:

对不起,我的英语不好:

1o Install Appserv

1o 安装应用服务

Filename: "appserv-win32-2.5.10.exe"

文件名:“appserv-win32-2.5.10.exe”

URL download: h*ttp://www.appservnetwork.com/ (without *)

网址下载:h*ttp://www.appservnetwork.com/(不带*)

Apache port: 8080

阿帕奇端口:8080

2o Download PHP 5.3(Apache 2.2 doesn't support superior)

2o 下载 PHP 5.3(Apache 2.2 不支持高级)

Filename: "php-5.3.29-Win32-VC9-x86.zip"

文件名:“php-5.3.29-Win32-VC9-x86.zip”

How?: Thread Safe

如何?:线程安全

URL Download: h*ttp://windows.php.net/download#php-5.6 (without *)

网址下载:h*ttp://windows.php.net/download#php-5.6(不带*)

3o Stop Apache

3o 停止 Apache

4o Delete all contents in the folder "..\AppServ\php5"

4o 删除文件夹“..\AppServ\php5”中的所有内容

5o Copy the zip contents to "..\AppServ\php5"

5o 将 zip 内容复制到“..\AppServ\php5”

6o Add line

6o 添加行

date.timezone = "America/Buenos_Aires" (This is my zone, find yours in php page)

date.timezone = "America/Buenos_Aires"(这是我的区域,在 php 页面中找到你的区域)

to the "php.ini" in "c:\Windows\php.ini"

到“c:\Windows\php.ini”中的“php.ini”

to avoid date error in PHP

避免 PHP 中的日期错误

7o Start Apache

7o 启动 Apache

=============================

==============================

IMAGIC(Once PHP 5.3 is installed)

IMAGIC(安装 PHP 5.3 后)

1o Instal?? Image magic 6.7(Not superior, PHP 5.3 doesn't support)

1o 安装?? Image magic 6.7(不高级,PHP 5.3 不支持)

Filename: "ImageMagick-6.7.9-9-Q16-windows-dll.exe"

文件名:“ImageMagick-6.7.9-9-Q16-windows-dll.exe”

URL download: http://ftp.icm.edu.pl/packages/ImageMagick/binaries/

网址下载:http: //ftp.icm.edu.pl/packages/ImageMagick/binaries/

2o Download Imagic

2o 下载图片

Filename: "php_imagick-3.1.2-5.3-ts-vc9-x86.zip"

文件名:“php_imagick-3.1.2-5.3-ts-vc9-x86.zip”

URL download: http://windows.php.net/downloads/pecl/releases/imagick/3.1.2/

网址下载:http: //windows.php.net/downloads/pecl/releases/imagick/3.1.2/

3o In the dir "php5/ext" add the file "php_imagick.dll" from the last zip download(other files doesn't care)

3o在目录“php5/ext”中添加上次下载的zip文件中的“php_imagick.dll”文件(其他文件不关心)

4o Add line

4o 添加行

extension=php_imagick.dll

扩展名=php_imagick.dll

to the "php.ini" in "c:\Windows\php.ini"

到“c:\Windows\php.ini”中的“php.ini”

5o Restart Apache

5o 重启 Apache