PHP | Gmagick levelimage() Function

The Gmagick::levelimage() function is an inbuilt function in PHP which is used to adjust the levels of an image by scaling the colors falling between specified white and black points to the full available quantum range.

Syntax:

mixed Gmagick::levelimage( float $blackPoint, float $gamma,
        float $whitePoint, int $channel = Gmagick::CHANNEL_DEFAULT )

Parameters: This function accept four parameters as mentioned above and described below:

  • $blackPoint: It specifies the image black point.
  • $gamma: It specifies the image gamma.
  • $whitePoint: It specifies the image white point.
  • $channel (Optional): It specifies any channel constant that is valid for the channel mode.

Return Value: This function returns TRUE on success.

Exceptions: This function throws GmagickException on error.



Below given programs illustrate the Gmagick::levelimage() function in PHP:

Used Image:

Program 1 (Level an image):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Level the image
$gmagick->levelimage(300000, 8, 10);
   
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>

chevron_right


Output:

Program 2 (Level an drawing):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
   
// Create a GmagickDraw object
$draw = new GmagickDraw();
   
// Set the color
$draw->setFillColor('white');
   
// Function to draw rectangle
$draw->rectangle(0, 0, 800, 400);
   
// Set the fill color
$draw->setFillColor('red');
   
// Set the font size
$draw->setfontsize(50);
   
// Annotate a text
$draw->annotate(30, 100, 'GeeksforGeeks');
   
// Use of drawimage function
$gmagick->drawImage($draw);
   
// Level the image
$gmagick->levelimage(0, 34, 30);
   
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/gmagick.levelimage.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.