Create A PNG

This example shows how to create a PNG file

<html>
<body>
<?php
 //create a 300 by 300 image
    $img=ImageCreate(300,300);
 //a black background
    $bgcolor=ImageColorAllocate($img,0,0,0);
 //red color
    $red=ImagecolorAllocate($img,255,0,0);
 //create a red rectangle
    Imagerectangle($img,50,50,150,250,$red);
 //create a filled red rectangle
    Imagefilledrectangle($img,50,170,150,270,$red);
 //create the png file
    ImagePNG($img,”sample.png”);
 //clean up resources
    ImageDestroy($img);
?>
<img src=”sample.png”>
</body>
</html>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*