How to use imagick in php

Imagick makes image manipulation in PHP extremely easy through an OO interface. Here is a quick example on how to make a thumbnail:

Example #1 Creating a thumbnail in Imagick

Using SPL and other OO features supported in Imagick, it can be simple to resize all files in a directory [useful for batch resizing large digital camera images to be web viewable]. Here we use resize, as we might want to retain certain meta-data:

Example #2 Make a thumbnail of all JPG files in a directory

This is an example of creating a reflection of an image. The reflection is created by flipping the image and overlaying a gradient on it. Then both, the original image and the reflection is overlayed on a canvas.

Example #3 Creating a reflection of an image

The above example will output something similar to:

This example illustrates how to use fill patterns during drawing.

Example #4 Filling text with gradient

The above example will output something similar to:

Working with animated GIF images

Example #5 Read in GIF image and resize all frames

Working with ellipse primitive and custom fonts

Example #6 Create a PHP logo

The above example will output something similar to:

vokseli

8 years ago

Be careful when loading multiple images by passing an array to a new Imagick object. This is from Example #2:



If you have lots of images inside the images folder, PHP will consume a lot of memory, ergo it is not recommended. I personally think it's a better idea to loop each image separately:



This way only a single image is fitted into the memory at a time.

inoshadi at gmail dot com

8 years ago

on Example #3 Creating a reflection of an image
----------------------------------------------------
/* Clone the image and flip it */
$reflection = $im->clone[];
$reflection->flipImage[];
----------------------------------------------------
it was using the Imagick::clone function

This function has been DEPRECATED as of imagick 3.1.0 in favour of using the clone keyword.

use below code instead:
----------------------------------------------------
/* Clone the image and flip it */
$reflection = clone $im;
$reflection->flipImage[];
----------------------------------------------------

//php.net/manual/en/imagick.clone.php

How do I add imagick to PHP?

Navigate to Home - Software - Module Installers, then click on the Manage button next to PHP Pecl. In the next screen, select the required PHP version, then click Apply. You can now enter “imagick” in the Install a PHP Pecl field, and click the Install Now button.

What is imagick PHP extension?

Imagick is a PHP extension to create and modify images using the ImageMagick library. There is also a version of Imagick available for HHVM. Although the two extensions are mostly compatible in their API, and they both call the ImageMagick library, the two extensions are completely separate code-bases.

How do I know if PHP imagick is installed?

To check whether ImageMagick is already installed on a Unix based system, try the following:.
Open a terminal - console window..
Execute the following command: convert -version..
If the ImageMagick version and other information is displayed, then you already have ImageMagick installed, and you can skip the next section..

How do I install imagick library?

To install it, download Visual C++ Redistributable Package. Congratulations, you have a working ImageMagick distribution under Windows and you are ready to use ImageMagick to convert, compose, or edit your images or perhaps you'll want to use one of the Application Program Interfaces for C, C++, Perl, and others.

Chủ Đề