PHP 7.1.0 Release Candidate 3 Released


(PHP 5 >= 5.5.0)

imagecropCrop an image using the given coordinates and size, x, y, width and height


resource imagecrop ( resource $image , array $rect )


Questa funzione, al momento non è documentata; è disponibile soltanto la lista degli argomenti.

Elenco dei parametri


Una risorsa immagine, restituita da una delle funzioni di creazione immagine, come imagecreatetruecolor().


Array with keys "x", "y", "width" and "height".

Valori restituiti

Return cropped image resource on success o FALSE in caso di fallimento.

add a note add a note

User Contributed Notes 2 notes

robert at woodst dot com
3 months ago
It appears that imagecrop() will output a black line along the bottom the resulting image until version 5.6.12. Your only choices are to upgrade PHP or use imagecopyresampled(). (bug #67447)
nangomusic at gmail dot com
2 years ago
An example to crop an image stored in $filename:

// Create a blank image and add some text
$ini_filename = 'test.JPG';
$im = imagecreatefromjpeg($ini_filename );

$ini_x_size = getimagesize($ini_filename )[0];
$ini_y_size = getimagesize($ini_filename )[1];

//the minimum of xlength and ylength to crop.
$crop_measure = min($ini_x_size, $ini_y_size);

// Set the content type header - in this case image/jpeg
//header('Content-Type: image/jpeg');

$to_crop_array = array('x' =>0 , 'y' => 0, 'width' => $crop_measure, 'height'=> $crop_measure);
$thumb_im = imagecrop($im, $to_crop_array);

imagejpeg($thumb_im, 'thumb.jpeg', 100);
To Top