function draw_bezier ($p0, $p1, $p2, $p3, $detail, $show_bounds
{
$x0$p0[0];$x1$p1[0];$x2$p2[0];$x3$p3[0];
$y0$p0[1];$y1$p1[1];$y2$p2[1];$y3$p3[1];
$cx=3*($x1$x0);
$bx=3*($x2$x1)-$cx
$ax$x3$x0$cx$bx
$cy=3*($y1$y0);
$by=3*($y2$y1)-$cy
$ay$y3$y0$cy$by
// generate the bezier points
for$i=0; $i<=$detail; $i++) {
$t = $i$detail
$x = $ax$t$t$t$bx$t$t$cx$t$x0
$y = $ay$t$t$t$by$t$t$cy$t$y0
$points$i] = array$x$y);
}
$width=400;
$height=400;
$imageimage_create_alpha$width$height);
$cimagecolorallocate$image,0,0,0);
$c2imagecolorallocate$image,200,200,200);
// determine scale so curve shows within our image
$minxmin$x0$x1$x2$x3);
$maxxmax$x0$x1$x2$x3);
$minymin$y0$y1$y2$y3);
$maxymax$y0$y1$y2$y3);
if ($maxx==$minx
$scale = ($height-1)/($maxy$miny);
else if ($maxy==$miny
$scale = ($width-1)/($maxx$minx);
else
$scale = min(($width-1)/($maxx$minx), ($height-1)/($maxy$miny));
if ($show_bounds) {
imageline$image, ($x0$minx)*$scale, ($y0$miny)*$scale, ($x1$minx)*$scale, ($y1$miny)*$scale, $c2);
imageline$image, ($x1$minx)*$scale, ($y1$miny)*$scale, ($x2$minx)*$scale, ($y2$miny)*$scale, $c2);
imageline$image, ($x2$minx)*$scale, ($y2$miny)*$scale, ($x3$minx)*$scale, ($y3$miny)*$scale, $c2);
}
// draw the bezier
for ($i=1;$icount$points);$i++) {
imageline$image, ($points$i-1][0]-$minx)*$scale, ($points$i-1][1]-$miny)*$scale, ($points$i][0]-$minx)*$scale, ($points$i][1]-$miny)*$scale, $c);
}
return $image
}