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

imagecreate

Description

The imagecreate of Image for PHP create a new palette based image.

Syntax

imagecreate(
    int $width,
    int $height
): GdImage|false

Parameters

width

The image width.

height

The image height.

Return

Returns an image object on success, false on errors.

Examples

1 · return

<?

$width = 100;
$height = 100;

$return = imagecreate($width, $height);

var_dump($return);
object(GdImage)#1 (0) {
}

2 · base64

<?

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

$red = 0;
$green = 0;
$blue = 0;
imagecolorallocate($image, $red, $green, $blue);

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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEUAAACnej3aAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAFElEQVQ4jWNgGAWjYBSMglFATwAABXgAAfmlXscAAAAASUVORK5CYII=">
</body>
</html>