imagecrop 


gd apg

CROPS an image to the given rectangular area.





$rectangle is an ARRAY with keys: x, y, width and height.

This function returns FALSE on failure.



<?php

GdImage
|false imagecrop GdImage $image, array $rectangle )


where,

$image The image identifier

$rectangle 
The parameters ARRAY of the rectangle to crop

?>
 

  $image   


The image resource returned by one of the image creation function.



  $rectangle   


The cropping rectangle parameters.



  1 EXERCISE   

<?php

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

$org_image "png/PNG 049 01.png";
$crp_image "png/PNG 049 01-cropped.png";

$crop_arr = [ "x" => 210"y" => 43
                               
"width" => 260"height" => 367 ];

echo 
$org_image?>
<br><br><img src="<?php echo 
$org_image?>" alt="<?php echo $org_image?>" width="400"><br><br>

<?php
$id_org_img 
imagecreatefrompng($org_image);


$arr_org_info getimagesize($org_image);

echo 
$arr_org_info[3] . '<br><br><br><br>';

$id_crp_img imagecrop($id_org_img$crop_arr );
imagepng ($id_crp_img$crp_image );

echo 
$crp_image?>
<br><br><img src="<?php echo 
$crp_image?>" alt="<?php echo $crp_image?>" width="200"><br><br>


<?php
$arr_crp_info 
getimagesize($crp_image);

echo 
$arr_crp_info[3];

?>  

 RESULT   

PNG 049 01.png

width="640" height="424"

PNG 049 01.png apr


PNG 049 01-cropped.png

width="260" height="367"

PNG 049 01-cropped.png apr