How to Adjust Image Saturation in PHP with Imagick – A Step‑by‑Step Guide
This tutorial explains how to install the Imagick extension for PHP and use its setImageAttribute() and setImageProperty() methods to modify an image's saturation, providing clear code examples and a concise summary of the process.
In this article, we introduce image saturation—the purity and vividness of colors—and demonstrate how to adjust it in PHP using the Imagick library.
1. Install Imagick Library
Before starting, ensure the Imagick extension is installed on the server. You can verify the installation with the following command: php -m | grep imagick If the output contains "imagick", the extension is installed; otherwise, install it according to your environment.
2. Change Image Saturation
2.1 setImageAttribute()
The setImageAttribute() method accepts a saturation value ranging from -100 (no saturation) to +100 (maximum saturation). Below is a sample code that sets the saturation to 50.
$imagick = new Imagick('input.png');
$imagick->setImageAttribute('saturation', 50);
$imagick->writeImage('output.png');
$imagick->destroy();2.2 setImageProperty()
Alternatively, you can use setImageProperty(), which works similarly to setImageAttribute(). The property name for saturation is "Saturation". The following example also sets saturation to 50.
$imagick = new Imagick('input.png');
$imagick->setImageProperty('Saturation', 50);
$imagick->writeImage('output.png');
$imagick->destroy();3. Summary
By using the Imagick extension in PHP, you can easily adjust an image's saturation, enhancing its color vibrancy. Beyond saturation, Imagick also supports many other image processing functions such as cropping and scaling.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
