Backend Development 4 min read

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.

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

login 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.