<?php
array imagegetclip ( GdImage $image )
where,
$image = The image identifier
?>
<?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_im01, 0, 0, 255);
$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>';
}
?>
<?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_im02, 0, 0, 255);
$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);
}
?>