(Answer) (Category) Products of Aardvarks With Chisels : (Category) HTML : (Category) PHP stuff :
triangle.php
Generate an equilateral triangle on the base of an image, then positions it within a range on the bottom of the image. The image would probably be a horizontal scale with values from 0 to $range.
http://www.cloudmaster.com/~sauer/demos/triangle.php
<?php
// generates a JPEG with an equilateral triangle of a given height on
// the base of an image, used as an indicator-type thing
header ("Content-type: image/jpeg");

// config vars ('n stuff)
$imageName = "images/response_indicator"; // base of image path
$rborder = 12;
$lborder = 6;
$tri_height = 8;
$tri_half_width = tan(30.0*(M_PI/180.0)) * (float)$tri_height; // Mmmm, trig...
$range = 20; // number of marks on bar
$quality = isset($Q) ? $Q : 93; // quality is int from 1-100

// calculate some stuff
if($CENTER >= 20){
        $imageName .= "_ready.png";
}else if($CENTER >= 10){
        $imageName .= "_smwtrdy.png";
}else{
        $imageName .= "_notrdy.png";
}
list($length, $height, $type, $str) = GetImageSize($imageName);
$length = $length - ($rborder + $lborder);
$CENTER *= $length / $range;
$CENTER += $lborder;

// load the image
$im = ImageCreateFromPNG($imageName);
$white = ImageColorAllocate($im, 255, 255, 255);

// build the image
$top = $height - $tri_height;
$lbott = $CENTER - ($tri_half_width);
$rbott = $CENTER + ($tri_half_width);
$points = array($CENTER, $top, $lbott, $height, $rbott, $height);
ImageFilledPolygon($im, $points, 3, $white);

// print the image
ImageJPEG($im, "", $quality);

ImageDestroy($im); // free up some memory
?>
[Append to This Answer]
2001-Nov-26 3:31pm
Previous: (Answer) snake.php
This document is: http://www.cloudmaster.com/~sauer/projects/index.cgi?file=117
[Search] [Appearance]
This is a Faq-O-Matic 2.719.
This FAQ administered by sauer@cloudmaster.com