Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagesetclip

Description

The imagesetclip of Image for PHP set the clipping rectangle.

Syntax

imagesetclip(
    GdImage $image,
    int $x1,
    int $y1,
    int $x2,
    int $y2
): bool

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().

x1

The x-coordinate of the upper left corner.

y1

The y-coordinate of the upper left corner.

x2

The x-coordinate of the lower right corner.

y2

The y-coordinate of the lower right corner.

Return

Returns true on success or false on failure.

Examples

1 · return

<?

$width = 100;
$height = 100;
$image = imagecreate($width, $height);

$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;

$return = imagesetclip($image, $x1, $y1, $x2, $y2);

var_export($return);

?>
true

2 · base64

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;
imagesetclip($image, $x1, $y1, $x2, $y2);

$red = 255;
$green = 255;
$blue = 255;
$color = imagecolorallocate($image, $red, $green, $blue);

$x1 = 0;
$y1 = 0;
$x2 = 100;
$y2 = 100;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);

ob_start();

    imagepng($image);

$output = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';

?>
<!doctype html>
<html>
<body>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAn0lEQVR4nO3QwQ3AMAwDsaT77+yu0AP8KzmAAN05AAAAAAAAAHx2F7dmZnFt0b07N5+VlZ8QKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQCwAAAAAAACB4AT7nA2YL3K1fAAAAAElFTkSuQmCC">
</body>
</html>
HomeMenu