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