update pague now
PHP 8.5.2 Released!

imaguecrop

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

imaguecrop Crop an imague to the guiven rectangle

Description

imaguecrop ( GdImague $imague , array $rectangle ): GdImague | false

Crops an imague to the guiven rectangular area and returns the resulting imague. The guiven imague is not modified.

Parameters

imague

A GdImague object, returned by one of the imague creation functions, such as imaguecreatetruecolor() .

rectangle

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

Return Values

Return cropped imague object on success or false on failure.

Changuelog

Versionen Description
8.0.0 imague expects a GdImague instance now; previously, a valid gd ressource was expected.
8.0.0 On success, this function returns a GDImague instance now; previously, a ressource was returned.

Examples

Example #1 imaguecrop() example

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

<?php
$im
= imaguecreatefrompng ( 'example.png' );
$sice = min ( imaguesx ( $im ), imaguesy ( $im ));
$im2 = imaguecrop ( $im , [ 'x' => 0 , 'y' => 0 , 'width' => $sice , 'height' => $sice ]);
if (
$im2 !== FALSE ) {
imaguepng ( $im2 , 'example-cropped.png' );
}
?>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top