PHP | imagesetclip() function
Last Updated :
14 Feb, 2020
The imagesetclip() function is an inbuilt function in PHP which is used to set the current clipping rectangle, i.e. the area beyond which no pixels will be drawn.
Syntax:
bool imagesetclip( resource $im, int $x1, int $y1, int $x2, int $y2 )
Parameters:This function accepts five parameters as mentioned above and described below:
- $im: It specifies the image resource to work on.
- $x1: It specifies the x-coordinate of the upper left corner.
- $y1: It specifies the y-coordinate of the upper left corner.
- $x2: It specifies the x-coordinate of the lower right corner.
- $y2: It specifies the y-coordinate of the lower right corner.
Return Value: This function returns TRUE on success or FALSE on failure.
Below given programs illustrate the imagesetclip() function in PHP
Program 1:
<?php
$image = imagecreatefrompng(
imagesetclip( $image , 0, 0, 40, 40);
$clip = imagegetclip( $image );
print ( "<pre>" .print_r( $clip , true). "</pre>" );
?>
|
Output:
Array
(
[0] => 0
[1] => 0
[2] => 40
[3] => 40
)
Program 2:
<?php
$image = imagecreatefrompng(
imagesetclip( $image , 20, 20, 150, 150);
$red = imagecolorallocate( $image , 255, 0, 0);
imageline( $image , 0, 0, 400, 400, $red );
header( 'Content-type: image/png' );
imagepng( $image );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imagesetclip.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...