PHP | Imagick functionImage() Function

The Imagick::functionImage() function is an inbuilt function in PHP which is used to apply an arithmetic, relational, or logical expression to a pseudo image.

Syntax:

bool Imagick::functionImage( int $function, array $arguments,
                     int $channel = Imagick::CHANNEL_DEFAULT )

Parameters: This function accepts three parameters as mentioned above and described below:



  • $function: This parameter holds the function to be applied.
  • $arguments: This parameter holds the array to be passed to the function.
  • $channel: This parameter holds the Imagick channel constants that provide any channel constant which is valid for channel mode. More than one channel can be combined using bitwise operators. The default value of channel constant is CHANNEL_DEFAULT.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::functionImage() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Imagick object
$imagick = new Imagick();
  
// Create the pseudo image
$imagick->newPseudoImage(800, 200, 'gradient:green-white');
  
// Apply the functionImage() functions
$imagick->functionImage(Imagick::FUNCTION_SINUSOID, array(1, -90));
  
header("Content-Type: image/png");
  
// Display the output image
$imagick->setImageFormat("png");
echo $imagick->getImageBlob();
  
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Imagick object
$imagick = new Imagick();
  
// Create the pseudo image
$imagick->newPseudoImage(800, 200, 'gradient:yellow-blue');
  
// Apply the functionImage() functions
$imagick->functionImage(Imagick::FUNCTION_POLYNOMIAL, array(6, -3, 1));
  
header("Content-Type: image/png");
  
// Display the output image
$imagick->setImageFormat("png");
echo $imagick->getImageBlob();
  
?>

chevron_right


Output:

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Imagick object
$imagick = new Imagick();
  
// Create the pseudo image
$imagick->newPseudoImage(800, 200, 'gradient:white-blue');
  
// Apply the functionImage() functions
$imagick->functionImage(Imagick::FUNCTION_SINUSOID, array(3, -90));
  
header("Content-Type: image/png");
  
// Display the output image
$imagick->setImageFormat("png");
echo $imagick->getImageBlob();
  
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagick.functionimage.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.



Improved By : nidhi_biet

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.