Open In App

PHP | imagesetclip() function

Last Updated : 14 Feb, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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
// Load the png image
$image = imagecreatefrompng(
  
// Set the clip
imagesetclip($image, 0, 0, 40, 40);
  
// Get the clip
$clip = imagegetclip($image);
print("<pre>".print_r($clip, true)."</pre>");
?>


Output:

Array
(
    [0] => 0
    [1] => 0
    [2] => 40
    [3] => 40
)

Program 2:




<?php
// Load the png image
$image = imagecreatefrompng(
  
// Set the clip
imagesetclip($image, 20, 20, 150, 150);
  
// Create a line from upper left corner to (400, 400)
// and you will see the line doesn't start from upper
// left corner because it is clipped from (20, 20)
$red = imagecolorallocate($image, 255, 0, 0);
imageline($image, 0, 0, 400, 400, $red);
  
// Output image to the browser
header('Content-type: image/png');
imagepng($image);
?>


Output:

Reference: https://www.php.net/manual/en/function.imagesetclip.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads