Sunday, June 14, 2026
HomeLanguagesPHP | Imagick contrastImage() Function

PHP | Imagick contrastImage() Function

The Imagick::contrastImage() function is an inbuilt function in PHP which is used to change the contrast of the image. This function enhances the intensity differences between the lighter and darker elements of the image.

Syntax:

bool Imagick::contrastImage(bool $sharpen)

Parameters: This function accepts a single parameter $sharpen which decides whether to increase or decrease the contrast.

Return Value: This function returns True on success.

Errors/Exceptions: This function throws ImagickException on error.

Below given programs illustrate the Imagick::contrastImage() function in PHP:

Program 1:




<?php
  
// Create new Imagick object
$imagick = new Imagick(
  
// Apply the contrastImage() function
$imagick->contrastImage(false);
  
header("Content-Type: image/png");
  
// Display the output image
echo $imagick->getImageBlob();
?>


Output:

Program 2:




<?php
  
// Create new Imagick object
$imagick = new Imagick(
  
// Apply the contrastImage() function
$imagick->contrastImage(true);
  
header("Content-Type: image/png");
  
// Display the output image
echo $imagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagick.contrastimage.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS