How to Adjust Image Saturation in PHP Using Imagick

This article explains how to install the Imagick extension on a server, then demonstrates two PHP methods—setImageAttribute() and setImageProperty()—to modify an image's saturation, providing complete code examples for each approach and summarizing the process.

php Courses
php Courses
php Courses
How to Adjust Image Saturation in PHP Using Imagick

1. Install Imagick

Before starting, ensure the Imagick extension is installed on the server. You can verify its presence with the command: php -m | grep imagick If "imagick" appears in the output, the extension is installed; otherwise, install it according to your environment.

2. Change Image Saturation

Imagick provides two methods to adjust saturation: setImageAttribute() and setImageProperty(). Both accept a saturation value ranging from -100 (no saturation) to +100 (maximum saturation).

2.1 Using setImageAttribute()

Example code:

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

This creates an Imagick object, loads "input.png", sets saturation to 50, writes the result to "output.png", and releases resources.

2.2 Using setImageProperty()

Example code:

$imagick = new Imagick('input.png');
$imagick->setImageProperty('Saturation', 50);
$imagick->writeImage('output.png');
$imagick->destroy();

The only difference is the use of setImageProperty() with the property name "Saturation". The rest of the workflow is identical.

3. Summary

By using the Imagick extension in PHP, you can easily adjust an image's saturation as well as perform other operations such as cropping and scaling. The two methods shown provide flexible ways to control color intensity.

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.