imagegetclip 


gd apg

RETRIEVES the current clipping rectangle, i.e. the area beyond which no pixels will be drawn.

This function is only available as of PHP 7.2.0





This function returns an indexed array with the coordinates of the clipping rectangle which has the following entries:

[0] x-coordinate of the upper left corner
[1] y-coordinate of the upper left corner
[2] x-coordinate of the lower right corner
[3] y-coordinate of the lower right corner



<?php

array imagegetclip GdImage $image )


where,

$image The image identifier

?>
 

  $im   


The image identifier.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$img01 'png/PNG 077 01.png';

$rct01 'png/PNG 077 01 imagegetclip.png';

echo 
basename($img01); ?> 
<br><br><img src="<?php echo  
$img01?>" alt="<?php echo $img01?>" width="400"><br><br>  

<?php

$id_im01 
imagecreatefrompng($img01);

$x01a 230;
$y01a 123;

$x01b 360;
$y01b 230;

$white imagecolorallocate($id_im0100255);

$bool01 imagesetclip($id_im01
                                     
$x01a$y01a$x01b$y01b);

if(
$bool01 == TRUE)
{
imagerectangle($id_im01
                         
$x01a$y01a$x01b$y01b$white);

imagepng($id_im01$rct01);    

echo 
basename($rct01); ?> 
<br><br><img src="<?php echo $rct01?>
alt="<?php echo $rct01?>" width="400"><br><br>
<?php
$arr_gtclip 
imagegetclip($id_im01);

echo 
'<pre>';
print_r($arr_gtclip);
echo 
'</pre>';

}

?>


 RESULT   

PNG 077 01.png

PNG 077 01.png apr

PNG 077 01 imagegetclip.png

PNG 077 01 imagegetclip.png apr

Array
(
[0] => 230
[1] => 123
[2] => 360
[3] => 230
)


  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$org_img "png/PNG 077 02.png";

$clp_img "png/PNG 077 02 imagegetclip.png";

$crp_img "png/PNG 077 02 imagegetclip crop.png";

echo 
basename($org_img); ?>
<br><br><img src="<?php echo $org_img?>
alt="<?php echo $org_img?>" width="400"><br><br>

<?php
$id_im02 
imagecreatefrompng($org_img);

$x01a 230;
$y01a 123;

$x01b 360;
$y01b 230;

$white imagecolorallocate($id_im0200255);

$bool02 imagesetclip($id_im02
                                     
$x01a$y01a$x01b$y01b);

if(
$bool02 == TRUE)
{
imagerectangle($id_im02$x01a$y01a
                                         
$x01b$y01b$white);

imagepng($id_im02$clp_img);    

echo 
basename($clp_img); ?> 
<br><br><img src="<?php echo  
$clp_img?>" alt="<?php echo $clp_img?>" width="400"><br><br>
<?php
$gtclip 
imagegetclip($id_im02);

print_r($gtclip);

$xa01a $gtclip[0]-1;
$ya01a $gtclip[1]-1;

$xb01b $gtclip[2]+1;
$yb01b $gtclip[3]+1;

$w01 = ($xb01b $xa01a);

$h01 = ($yb01b $ya01a);

$crop = [ "x" => $xa01a"y" => $ya01a
                              
"width" => $w01"height" => $h01 ];

$id_im03 imagecrop($id_im02$crop );
imagepng ($id_im03$crp_img );

echo 
'<br><br>' basename($crp_img); ?>
<br><br><img src="<?php echo $crp_img?>
alt="<?php echo $crp_img?>" width="90"><br><br>

<?php
print_r
($crop);

}

?> 


 RESULT   

PNG 077 02.png

PNG 077 02.png apr

PNG 077 02 imagegetclip.png

PNG 077 02 imagegetclip.png apr

Array ( [0] => 230 [1] => 123 [2] => 360 [3] => 230 )

PNG 077 02 imagegetclip crop.png

PNG 077 02 imagegetclip crop.png apr

Array ( [x] => 229 [y] => 122 [width] => 132 [height] => 109 )

This image crop was done using a combination of the imagegetclip and imagecrop functions.