PHP.nl

imagecrop

imagecrop

Crop an image to the given rectangle

 **imagecrop** GdImage $image array $rectangle

Crops an image to the given rectangular area and returns the resulting image. The given is not modified. image

rectangle The cropping rectangle as with keys , , and . array``x``y``width``height

Return cropped image object on successreturn.falseforfailure.

Voorbeeld: example

This example shows how to crop an image to a square area.

<?php
$im = imagecreatefrompng('example.png');
$size = min(imagesx($im), imagesy($im));
$im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]);
if ($im2 !== FALSE) {
    imagepng($im2, 'example-cropped.png');
}
?>

imagecropauto