Adjusting Image Hue with PHP Imagick

This guide explains how to install the PHP Imagick extension and use its Imagick class to load an image, adjust its brightness, saturation, and hue with modulateImage, and then save or output the modified image, providing complete example code.

php Courses
php Courses
php Courses
Adjusting Image Hue with PHP Imagick

When developing web applications, adjusting an image's hue is a common requirement; the PHP Imagick library provides powerful image manipulation capabilities, including scaling, cropping, rotating, and applying filters.

First, install the Imagick extension: sudo apt-get install php-imagick After the extension is installed, you can start using Imagick to modify image tones.

Create an Imagick object and load the target image:

$image = new Imagick();
$image->readImage('path/to/image.jpg');

Use the modulateImage method to adjust brightness, saturation, and hue. The method accepts three parameters (brightness, saturation, hue) ranging from -100% to +100%, where 0% leaves the value unchanged.

For example, to set the brightness to 50% of the original: $image->modulateImage(100, 50, 100); After adjusting the tone, save the modified image to a file: $image->writeImage('path/to/new_image.jpg'); Alternatively, output the image directly to the browser:

header('Content-type: image/jpeg');
$image->setImageFormat('jpeg');
echo $image;

Full example code combining the steps above:

$image = new Imagick();
$image->readImage('path/to/image.jpg');
$image->modulateImage(100, 50, 100);
$image->writeImage('path/to/new_image.jpg');

The code loads an image, adjusts its hue (brightness, saturation, hue), and saves the result.

Using Imagick to adjust image tones is straightforward and requires only a few lines of code; by tweaking brightness, saturation, and hue you can achieve a wide range of visual effects, making Imagick a flexible tool for image processing tasks.

Java learning material download

C language learning material download

Frontend learning material download

C++ learning material download

PHP learning material download

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 DevelopmentPHPHue Adjustment
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.