php imagemagick庫安裝使用

imagemagick介紹:php

ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 100) including DPXEXR, GIF, JPEG, JPEG-2000, PDF, PNG, Postscript, SVG, and TIFF. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.html

The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite language. Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++),JMagick (Java), L-Magick (Lisp), LuaNMagick (Neko/haXe), Magick.NET (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP(PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images dynamically and automagically.java

ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you may use, copy, modify, and distribute in both open and proprietary applications. It is distributed under the Apache 2.0 license, approved by the OSI and recommended for use by the OSSCC.python

The ImageMagick development process ensures a stable API and ABI. Before each ImageMagick release, we perform a comprehensive security assessment that includes memory error and thread data race detection to prevent security vulnerabilities.linux

The current release is ImageMagick 6.9.0-3 available from http://www.imagemagick.org/download. It runs on LinuxWindowsMac Os XiOS, Android OS, and others.web

The authoritative ImageMagick web site is http://www.imagemagick.org.apache

著名的圖片服務提供商 Flickr 使用的是ImageMagick,還有 Yupoo 、 手機之家 使用的也是ImageMagick。windows

下載:http://www.imagemagick.org/download/api

windows安裝:ruby

下載windows版:

 安裝後,在安裝php擴展:官方推薦的3個:

MagickWand for PHP a native PHP-extension to the ImageMagick MagickWand API.

IMagick is a native PHP extension to create and modify images using the ImageMagick API. Documentation for the extension is available here.

phMagick is a wrapper class for ImageMagick, wrapping the most common web image manipulation actions in easy to use functions, but allowing full access to ImageMagick's power by issuing system calls to it's command-line programs.

決定使用Imagick。

windows下在iMagick的dll擴展 http://pecl.php.net/package/imagick 

重命名爲php_imagick.dll 而後copy到php的ext文件夾下
   在php.ini文件中添加設置
   extension=php_imagick.dll
   以後查看phpinfo() 裏面有沒有imagick一欄,若是有的話就能夠進行測試了。

 (

php5.4.x or php5.5.x 

dyn = dynamic, st = static, q16 = 16 bit, q8= 8 bit.

以上標識,同你下載的ImageMagick下載標識相同,本人用的是q16 。安裝路徑不要有空格。

5. 把dll文件重命名爲php_imagick.dll,並放到php 擴展文件目錄 php/ext 中。

6. 在 php.ini 配置文件中添加,extension=php_imagick.dll。

7. 重啓電腦,只重啓apache無論用的狀況下,重啓下PC。由於擴展底層使用的是imageMagic軟件,因此軟件重啓電腦,從新加載軟件,並刷新path路徑。

 

我老是報錯:

「  系統錯誤 ,沒法啓動此程序由於計算機丟失CORE_RL_wand_.dll 」 

把下載php_imagick-3.4.3-5.5-ts-vc11-x86下面的全部dll放在windows system32下面仍是不行,最後看了一篇博客,

 (解決了,把擴展包中的「CORE_*.dll」 這些dll文件 放到 你的php.exe同級目錄下

若是沒有Imagick 項,請 使用 php擴展調試命令  來檢查擴展中存在的問題, 並確保三方軟件版本一致便可。

php擴展  調試命令:

在cmd運行:  php --ri imagick

 

1. 若是報錯是:「php_imagick.dll' - %1 不是有效的 Win32 應用程序」 ,則說明版本不相符合。 須要檢查   imagick軟件自己( 如x86)、php自己( x86 ts (thread safe) )、php擴展php_imagick.dll (ts) 三方版本 要一致。

 

2. 若是報錯是:「php.exe - 系統錯誤 ,沒法啓動此程序由於計算機丟失CORE_RL_wand_.dll 」 , 說明你沒有將 php_imagick-3.3.0-5.4-ts-vc9-x86.zip 擴展包中的「CORE_*.dll」 這些dll文件 放到 你的php.exe同級目錄下。   ,只須要拷貝 CORE_*.dll 到php目錄就能夠解決了。

 

3. 若是php --ri imagick 顯示的結果  ImageMagick number of supported formats:  => 0 支持的圖片格式數量爲0,請看第5步須要新建一個環境變量。

4.若是php代碼執行調用時報錯:「 NoDecodeDelegateForThisImageFormat 」,代表你的php_imagick.dll的版本 並不支持或並不匹配 ImageMagick軟件版本,這時候 php --ri imagick 的結果也顯示爲: ImageMagick number of supported formats => 0 。須要更換ImageMagick軟件版本。 

http://www.cnblogs.com/wangqishu/p/5609950.html

參考:http://blog.sina.com.cn/s/blog_966e43000101bgqj.html

 

 

LInux安裝:

下載源代碼:

參考官方教程:

cd ImageMagick-6.9.0

./configure

make

make install

執行:/usr/local/imagemagick/bin/convert logo: logo.gif 測試一下ImageMagick是否能夠正常運行。

(源碼安裝我有點問題,sudo apt-get install imagemagick

安裝完後

/usr/bin下有工具軟件

convert -version 能正常輸出。

我用這種方式,後面安裝php imagick出現問題:

checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

在網上搜了說要裝:

apt-get install libmagickwand-dev libmagickcore-dev

 

apt-get install libmagickwand-dev libmagickcore-dev
安裝後果真沒有問題了,結果:

Installing shared extensions: /opt/lampp/lib/php/extensions/no-debug-non-zts-20121212/
Installing header files: /opt/lampp/include/php/

 

或者:convert -version

二、安裝PHP擴展:imagick

最新的包能夠在下面的地址中找到http://pecl.php.net/package/imagick

1
2
3
4
5
6
7
8
9
10
11
12
wget http://pecl.php.net/get/imagick-3.0.1.tgz
tar zxvf imagick-3.0.1.tgz
cd imagick-3.0.1/
export PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick
make && make install

/usr/local/php_fcgi/bin/phpize
./configure --with-php-config=/usr/local/php_fcgi/bin/php-config --with-imagick=/usr/local/imagemagick
make && make install
cd ../

編輯/usr/local/php/etc/php.ini 添加:extension = "imagick.so"

編輯/usr/local/php_fcgi/etc/php.ini 添加:extension = "imagick.so"

重啓php-fpm或apache。

lu-restart

先試試,再執行:ldconfig ,從新加載一些連接庫。

(我用的是pecl install imagick 安裝,安裝完後提示:

You should add "extension=imagick.so" to php.ini

增長就好了。)

 

php_imagick程序示例

1.建立一個縮略圖並顯示出來
<?php
    header('Content-type: image/jpeg');
    $image = new Imagick('image.jpg');
    // If 0 is provided as a width or height parameter,// aspect ratio is maintained
    $image->thumbnailImage(100, 0);
    echo $image;
?>

2.建立一個目錄下的縮略圖,並保存
<?php
    $images = new Imagick(glob('images
    $im = new Imagick("example.gif");
    
    foreach ($im as $frame) {
    
    $frame->thumbnailImage(50, 50);
    
    $frame->setImagePage(50, 50, 0, 0);
    }
    $im->writeImages("example_small.gif", true);
?>

http://blog.sina.com.cn/s/blog_8da982ac010171iz.html

http://blog.csdn.net/andy1219111/article/details/38335987

http://blog.csdn.net/czloveyeer/article/details/8179766

 

http://blog.lizhigang.net/archives/228

文檔:

http://php.net/manual/zh/book.imagick.php

http://www.bitscn.com/pdb/php/201407/235972.html

http://wenku.baidu.com/view/7b83e46f67ec102de3bd893f.html

相關文章
相關標籤/搜索