PHP | Gmagick removeimageprofile() Function

The Gmagick::removeimageprofile() function is an inbuilt function in PHP which is used to remove the named image profile and returns it. This function works like the pop function of the stack data structure as it gives the value of profile and removes it from the image.

Syntax:

string Gmagick::removeimageprofile( string $name )

Parameters: This function accepts a single parameter $name which holds the name of profile to remove.

Return Value: This function returns a string value containing the value of the profile image.

Exceptions: This function throws GmagickException on error.



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

Used Image:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Create a profile
$gmagick->setimageprofile('profile_name', 'profile_value');
  
echo '<b>Before removing:</b> <br>';
  
// Test it using the function
testProfile($gmagick, 'profile_name');
  
// Remove the profile
$gmagick->removeimageprofile('profile_name');
  
echo '<b>After removing:</b> <br>';
// Test again if it is removed or not.
testProfile($gmagick, 'profile_name');
  
// Function to check if a profile is removed or not
function testProfile($gmagick, $name) {
  
    try {
        $value = $gmagick->getimageprofile('profile_name');
        echo 'Profile is available with name <i>' . $name .
                ' </i>and value <i>' . $value . '</i><br>';
  
    } catch (Exception $e) {
        echo 'Profile is not available.<br>';
    }
}
?>

chevron_right


Output:

Before removing:
Profile is available with name profile_name and value profile_value
After removing:
Profile is not available.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Set the Image Profiles
$gmagick->setimageprofile('borderColor1', 'green');
$gmagick->setimageprofile('borderColor2', 'red');
  
// Use the Image Profile
$gmagick->borderImage($gmagick->getImageProfile('borderColor1'), 6, 6);
  
// Use the Image Profile
$gmagick->borderImage($gmagick->getImageProfile('borderColor2'), 6, 6);
  
// Removing the profiles after use for memory efficiency
$gmagick->removeimageprofile('borderColor1');
$gmagick->removeimageprofile('borderColor2');
  
// Display the image
header("Content-Type: image/png");
echo $gmagick;
?>

chevron_right


Output:

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