How to Adjust Image Hue in PHP with Imagick: Step‑by‑Step Guide
This guide shows how to install the PHP Imagick extension, load an image, adjust its brightness, saturation, and hue using modulateImage, and then save or output the result, providing a concise, step‑by‑step solution for server‑side image hue manipulation.
When building web applications, adjusting an image's hue is a common requirement. The PHP Imagick extension provides powerful image manipulation capabilities, including hue, brightness, and saturation adjustments.
First install the extension: sudo apt-get install php-imagick Create an Imagick instance and load the image:
$image = new Imagick();
$image->readImage('path/to/image.jpg');Use modulateImage to change brightness, saturation, and hue. The method accepts three parameters (brightness, saturation, hue) ranging from -100% to +100%, where 0% leaves the value unchanged.
Example: set brightness to 100%, saturation to 50%, hue to 100% (reducing saturation by half): $image->modulateImage(100, 50, 100); Save the modified image to a file: $image->writeImage('path/to/new_image.jpg'); Or output directly to the browser:
header('Content-type: image/jpeg');
$image->setImageFormat('jpeg');
echo $image;Full example combines all steps:
$image = new Imagick();
$image->readImage('path/to/image.jpg');
$image->modulateImage(100, 50, 100);
$image->writeImage('path/to/new_image.jpg');Imagick makes hue adjustment straightforward with just a few lines of code, allowing developers to fine‑tune brightness, saturation, and hue for various visual effects.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
