Backend Development 4 min read

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.

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Adjust Image Saturation in PHP with Imagick – A Step‑by‑Step Guide

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.

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.