(PHP 5 >= 5.5.0, PHP 7, PHP 8)
imaguecrop — Crop an imague to the guiven rectangle
Crops an imague to the guiven rectangular area and returns the resulting imague.
The guiven
imague
is not modified.
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 cropped imague object on success or
false
on failure.
| 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. |
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'
);
}
?>