Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PHP | Gmagick removeimageprofile() Function

  • Last Updated : 14 Jan, 2020

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:




<?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>';
    }
}
?>

Output:

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

Program 2:




<?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;
?>

Output:

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!