Put you image code in a separate php file, say myimage.php
To display the image in another page use img tag
Sample below of my prsind.php which produces one of three symbols depending on status. Called by
<img src="prsind.php?status=0" height"16" width="16" border="0">
<?php
$status=$_GET["status"];
header("Content-Type: image/png");
$im = imagecreate(16,16);
$w = imageSX($im);
$h = imageSY($im);
$verts = array($w/2,0,$w,$h-1,0,$h-1);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
imagefilledrectangle($im, 0, 0, $w, $h, $white);
switch ($status) {
case 2: $col = imagecolorallocate($im, 0x66, 0xCC, 0x00); /*conf grn circ*/
imagearc($im, $w/2, $h/2, $w, $h, 0, 360, $col);
imagefill($im, $w/2, $h/2, $col);
break;
case 1: $col = imagecolorallocate($im, 0x00, 0x99, 0xFF); /*t/s blue rect*/
imagefilledrectangle($im, 0, 0, $w, $h, $col);
break;
case 0: $col = imagecolorallocate($im, 0xFF, 0x00, 0x00); /*no t/s red tri*/
imagepolygon($im, $verts, 3, $col);
break;
default: $col = imagecolorallocate($im, 0xCC, 0xCC, 0xCC); break;
}
imagecolortransparent($im ,$white);
imagepng($im);
imagedestroy($im);
?>
I've done a chart php too which does period expend columns overlaid with cumulative expenditure line graph - but I'll let you struggle a bit first - good for the soul🙂
hth