php Creating and Drawing Images

Here is an example to make black square on a white background (black.php)

<?php
$image = imagecreate(200, 200);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
imagefilledrectangle($image, 50, 50, 150, 150, $black);
header("Content-Type: image/png");
imagepng($image);
?>

A black square on a white background
A black square on a white background

Now use as an image

<img src="black.php" />

Leave a Comment