How to Adjust Image Saturation in PHP with Imagick – Step-by-Step Guide

Learn how to install the Imagick extension on your server and use its setImageAttribute() and setImageProperty() methods in PHP to modify an image's saturation, with clear code examples demonstrating both approaches and a brief summary of the process.

php Courses
php Courses
php Courses
How to Adjust Image Saturation in PHP with Imagick – Step-by-Step Guide

Install Imagick

Verify that the Imagick extension is loaded in PHP: php -m | grep imagick If the command returns imagick, the extension is available. Otherwise install it using the appropriate method for your environment (e.g., apt-get install php-imagick, yum install php-pecl-imagick, or pecl install imagick).

Adjust Image Saturation

Imagick provides two methods to modify an image's saturation: setImageAttribute() and setImageProperty(). Both accept a numeric value in the range -100 (completely desaturated) to +100 (maximum saturation).

Using setImageAttribute()

$imagick = new Imagick('input.png');
$imagick->setImageAttribute('saturation', 50); // value between -100 and 100
$imagick->writeImage('output.png');
$imagick->destroy();

Using setImageProperty()

$imagick = new Imagick('input.png');
$imagick->setImageProperty('Saturation', 50); // property name is case‑sensitive
$imagick->writeImage('output.png');
$imagick->destroy();

Both examples create an Imagick object, load the source image, set the saturation, write the modified image to a new file, and release the object.

Additional Notes

The attribute name for setImageAttribute() is case‑insensitive; use 'saturation'.

For setImageProperty() the property name must be capitalized as 'Saturation'.

Values outside the -100 to +100 range are clamped by ImageMagick.

After adjusting saturation, the same Imagick instance can perform other operations such as cropping or resizing.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Image ProcessingBackend DevelopmentPHPsaturationimagick
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.