How to Adjust Image Hue in PHP with Imagick: Step-by-Step Guide
Learn how to install the Imagick extension on PHP, create an Imagick object, load an image, and use the modulateImage method to adjust brightness, saturation, and hue, then save or output the modified image, with complete example code provided.
When building web applications you often need to modify image tones. PHP's Imagick extension offers powerful image manipulation capabilities, including adjustments to hue, brightness, and saturation.
First install the extension: sudo apt-get install php-imagick Create an Imagick instance and load the target image:
$image = new Imagick();
$image->readImage('path/to/image.jpg');Adjust the tone using modulateImage. The method accepts three parameters—brightness, saturation, and hue—each ranging from -100% to +100% (0% leaves the value unchanged). For example, to reduce saturation to 50% while keeping brightness and hue unchanged: $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 combining all steps:
$image = new Imagick();
$image->readImage('path/to/image.jpg');
$image->modulateImage(100, 50, 100);
$image->writeImage('path/to/new_image.jpg');This short script demonstrates loading an image, adjusting its tone, and persisting the result, showing how Imagick makes image processing in PHP straightforward.
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.
