Extended to animated GIF images with PHP installation Imagick

Source: Internet
Author: User
Tags imagemagick

Extended to animated GIF images with PHP installation Imagick



All along, PHP processing pictures are in the mainstream of GD, until recent years, the use of Imagick gradually become more.

GD is usually used to scale the image, to the image of water and other basic functions, such as the production of complex effects such as icon buttons, image reflection and other filter functions will be overwhelmed.

Especially for multi-frame images of animated GIF water printing, if the use of GD like ordinary jpg to play watermark, after the watermark after the picture only left the first frame, no dynamic effect.

Imagick will be able to do a good job of this, so that PHP to dynamic GIF image water printing is possible, and it also has a small memory footprint, high-quality features.

The following is the use of GD (left) and Imagick (right) to zoom the picture to 256px effect, please note the details of the picture.



Below I will describe in detail "How PHP installs Imagick extensions" and the example shows how to watermark animated GIF images.



There are two ways to use Imagick:

1. Command-line downgrade with the convert command

2.php Call Function library Imagick (requires 1 as installation base)



Pre-Installation Preparation (ImageMagick 6.8.8+, PHP 5.1.3+.), install the required library files first

Yum install tcl-devel.x86_64 libpng-devel.x86_64 libjpeg-devel.x86_64 ghostscript-devel.x86_64 bzip2-devel.x86_64 Freetype-devel.x86_64 libtiff-devel.x86_64

Yum install libjpeg-devel.x86_64 libpng-devel.x86_64 glib2-devel.x86_64 fontconfig-devel.x86_64 zlib-devel.x86_64 libwmf-devel.x86_64 freetype-devel.x86_64 libtiff-devel.x86_64libjpeg-devel libpng-devel glib2-devel Fontconfig-devel zlib-devel libwmf-devel freetype-devel libtiff-devel

Download ImageMagick and compile the installation
Wget-c http://www.imagemagick.org/download/ImageMagick.tar.gz

TAR-ZXVF ImageMagick.tar.gz

CD imagemagick-6.8.8-10

./configure--prefix=/usr/local/imagemagick--with-bzlib=yes--with-fontconfig=yes--with-freetype=yes--with-gslib =yes--with-gvc=yes--with-jpeg=yes--with-jp2=yes--with-png=yes--with-tiff=yes

Make && make install

Jpeg_default_qtables Error

Not looking for libjpg.

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

TAR-XZVF jpegsrc.v9.tar.gz

CD jpeg-9

./configure

Make libdir=/usr/lib64

Make libdir=/usr/lib64 Install

Ldconfig/usr/lib64


sudo ldconfig/usr/local/lib

(The compilation and installation process takes a long time, please wait patiently.) The path to convert after installation is/usr/local/bin/convert, and you can run "convert-version" directly from the command line to see the version. If a similar error is found, convert:error while loading shared libraries:libmagickcore.so.3:cannot open Shared object file:no such file o R directory, you can perform "ldconfig/usr/" to reload the path to the library file. )

Here imagemagic command-line tool has been installed, that is, the "convert" command, the execution of the next command will generate a logo.gif picture is the command line under the Imagemagic installation is complete, come to experience it.

cd/usr/local/nginx/html/
/usr/local/bin/convert Logo:logo.gif

Visit http://www.nginx.cn/logo.gif

If you can see this picture it means that the installation is correct.


Example of an advanced command order:

Cut 200x200 square picture from the middle

Convert 1.jpg-gravity center-extent 200x200 2.jpg

The resulting picture has a minimum edge of 500 pixels.

Convert 1.jpg-resize 500x500^ 2.jpg

Synthesize A, see how powerful, you put a picture of 200x300 around, this command will be the smallest side of the picture to scale forcibly expanded to 500 pixels, and then cut from the central 200 pixels in a positive way

Convert 1.jpg-resize 500x500^-gravity center-extent 200x200 2.jpg

Add a sy.png watermark to the picture base.jpg in y100,x10 position

Composite-geometry +100+10 sy.png base.jpg finished.jpg

Please refer to the official manual for detailed features.

http://www.imagemagick.org/Usage/

PHP Add imagick extension function

1. PHP Native Library Imagick
wget http://pecl.php.net/get/imagick-3.1.1.tgz
Tar zxvf imagick-3.1.1.tgz
CD IMAGICK-3.1.1/
/usr/local/php/bin/phpize
Ln-s/usr/local/include/imagemagick-6/usr/local/include/imagemagick
./configure--with-php-config=/usr/local/php/bin/php-config
Make
Make install

/usr/local/php Replace with your PHP installation path and verify that the Php-config file exists in the bin directory

Successful compilation will generate imagick.so in PHP extension directory
Location is
Installing Shared extensions:
/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
Installing header files:
/usr/local/php/include/php/

2.php Loading Imagick Library
Modify PHP.ini, add a line to the end of the file
Extension = "imagick.so"

How do I find the location of php.ini?
Perform
/usr/local/php/bin/php--ini
The path of php.ini is displayed, and there is no php.ini file under the path.
Configuration File (php.ini) Path:/usr/local/php/lib
Loaded Configuration File: (None)
Scan for additional. ini files in: (none)
Additional. ini files parsed: (none)

We can create a new empty php.ini and add a line Extension = "imagick.so"
Vi/usr/local/php/lib
Increase

Extension = "imagick.so"

3. Check the phpinfo to confirm that the Imagick was successfully loaded

Using the Imagick library to produce thumbnails, Logo.gif is a previously produced picture with the command line
[PHP]
<?php
Header (' Content-type:image/jpeg ');

$image = new Imagick (' logo.gif ');
$image->adaptiveresizeimage (1024,768);

Echo $image;
?>
[/php]

Visit: htt://www.nginx.cn/p.php


[PHP]
<?php
$image = new Imagick (' old.gif ');
$image = $image->coalesceimages ();
foreach ($image as $frame) {
$frame->thumbnailimage (50, 50);
}
$image = $image->optimizeimagelayers ();
$image->writeimages (' New.gif ', true);
?>
[/php]

Errors encountered during installation:
magick/.libs/libmagickcore.so:undefined reference to ' gzseek64 '
magick/.libs/libmagickcore.so:undefined reference to ' Gztell64 '
magick/.libs/libmagickcore.so:undefined reference to ' Gzopen64

Literally can't find 64 for the zlib, that is not the correct link to 64 zlib path, we can install 64 zlib and add its path to the command line (recommended way).

Specific steps

Ldconfig-v |grep Libz
Show that the library is 32-bit, so the connection failed
Libz.so.1-libz.so.1.2.3

wget http://zlib.net/zlib-1.2.8.tar.gz
TAR-ZXVF zlib-1.2.8.tar.gz
CD zlib-1.2.8

Cflags=-fpic./configure--libdir=/usr/lib64--prefix=/usr
Make
Make install

Cd.. /imagemagick-6.8.6-10/

./configure--with-zlib-dir=/usr/local/lib/

Make

If compiling or error, you can move the libz.so.1.2.3 to another location

mv/usr/lib/libz.so.1.2.3 ~

Ldconfig-v |grep Libz
Libz.so.1-libz.so.1.2.8

And make is a success.

Checking for MagickWand.h header file ... configure:error:Cannot locate header file MagickWand.h

The new ImageMagick path has been modified, and a soft connection to the default path needs to be established

Ln-s/usr/local/include/imagemagick-6/usr/local/include/imagemagick

Resources

Http://valokuva.org/?cat=1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.