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

imageline

Description

The imageline of Image for PHP draw a line.

Syntax

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

Parameters

image

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

x1

x-coordinate for first point.

y1

y-coordinate for first point.

x2

x-coordinate for second point.

y2

y-coordinate for second point.

color

The line color. A color identifier created with imagecolorallocate().

Return

Returns true on success or false on failure.

Examples

1 · return

<?

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

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

$x1 = 0;
$y1 = 0;
$x2 = 100;
$y2 = 100;

$return = imageline($image, $x1, $y1, $x2, $y2, $color);
    
var_export($return);

?>
true

2 · base64

<?

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

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

$x1 = 0;
$y1 = 0;
$x2 = 100;
$y2 = 100;
imageline($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/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA1ElEQVR4nO3QMQEAMBADofdvOrXQ20ECt+3456vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1fhqfDW+Gl+Nr8ZX46vx1Wx7Tngq5DAmlEsAAAAASUVORK5CYII=">
</body>
</html>
HomeMenu