How to Use the Built-in Imagick Module in ServBay
As a powerful integrated web development tool, ServBay comes with the Imagick module, and its activation process is very simple. Imagick is a PHP extension used to create and modify images, based on the ImageMagick library. With ServBay, developers can easily enable the Imagick module to use Imagick for image processing in PHP applications.
Introduction to the Imagick Module
Imagick is a powerful PHP extension that provides rich image processing capabilities. It supports various image formats and can perform complex image operations such as resizing, rotating, cropping, adding effects, and more.
Main Features
- Multi-format Support: Imagick supports various image formats, including but not limited to JPEG, PNG, GIF, TIFF, and more.
- Powerful Image Processing: Imagick provides rich image processing features such as resizing, rotating, cropping, adding watermarks, applying filters, and more.
- High Performance: Based on the ImageMagick library, Imagick offers efficient image processing performance, suitable for handling large batches of images.
- Ease of Use: Imagick provides an object-oriented API, allowing developers to easily perform image processing operations in PHP code.
Built-in Imagick Module Version in ServBay
ServBay supports multiple PHP versions and comes pre-installed with the corresponding Imagick module enabled by default for each version. The currently included Imagick module version is 3.7.0, but it may vary across different PHP versions, so please refer to the actual version in use.
How to Enable the Imagick Module
By default, the Imagick module is enabled, requiring no additional configuration.
Using Imagick in PHP Code
Once the Imagick module is enabled, you can use Imagick for image processing in PHP code. Here is a simple example:
Example Code
<?php
/* Read the image */
$im = new Imagick("test.png");
/* Thumbnail the image */
$im->thumbnailImage(200, null);
/* Create a border for the image */
$im->borderImage(new ImagickPixel("white"), 5, 5);
/* Clone the image and flip it */
$reflection = $im->clone();
$reflection->flipImage();
/* Create gradient. It will be overlayed on the reflection */
$gradient = new Imagick();
/* Gradient needs to be large enough for the image and the borders */
$gradient->newPseudoImage($reflection->getImageWidth() + 10, $reflection->getImageHeight() + 10, "gradient:transparent-black");
/* Composite the gradient on the reflection */
$reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0);
/* Add some opacity. Requires ImageMagick 6.2.9 or later */
// $reflection->setImageOpacity( 0.3 );
/* Create an empty canvas */
$canvas = new Imagick();
/* Canvas needs to be large enough to hold the both images */
$width = $im->getImageWidth() + 40;
$height = ($im->getImageHeight() * 2) + 30;
$canvas->newImage($width, $height, new ImagickPixel("black"));
$canvas->setImageFormat("png");
/* Composite the original image and the reflection on the canvas */
$canvas->compositeImage($im, imagick::COMPOSITE_OVER, 20, 10);
$canvas->compositeImage($reflection, imagick::COMPOSITE_OVER, 20, $im->getImageHeight() + 10);
/* Output the image*/
header("Content-Type: image/png");
echo $canvas;
?>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Conclusion
ServBay provides an easy way to manage and enable the Imagick module. With simple configuration and restart operations, developers can quickly enable the Imagick module in different PHP versions, thereby using Imagick for image processing in PHP applications. The multi-format support, powerful image processing capabilities, and high performance of Imagick make it an indispensable solution for image processing in modern web development. Through ServBay and Imagick, developers can build feature-rich and responsive web applications.