PHP | Gmagick trimimage() function
Last Updated :
23 Jan, 2020
The Gmagick::trimimage() function is an inbuilt function in PHP which is used to remove edges that are the background color from the image.
Syntax:
Gmagick Gmagick::trimimage( float $fuzz )
Parameters:This function accepts a single parameter $fuzz which holds the fuzz.
Return Value: This function returns TRUE on success.
Exceptions: This function throws GmagickException on error.
Below given programs illustrate the Gmagick::trimimage() function in PHP:
Program-1 (Trimming an image):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagick ->trimimage(10);
header( 'Content-type: image/png' );
echo $gmagick ;
?>
|
Output:
Program-2 (Trimming a drawing):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$draw ->setFillColor( 'white' );
$draw ->rectangle(0, 0, 800, 400);
$draw ->setFillColor( 'red' );
$draw ->setfontsize(50);
$draw ->annotate(30, 100, 'GeeksforGeeks' );
$gmagick ->drawImage( $draw );
$gmagick ->trimimage(10);
header( "Content-Type: image/png" );
echo $gmagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagick.trimimage.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...