<?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
?> |