<?php
/*
ScaleJPG ver 1.0.0
Author: Daniel Kushner
Email: daniel@websapp.com
Release: 18 Nov 2001
Copyright 2001
*/
class ScaleJPG {
var $im;
var $bgcolor = array(255,255,255);
var $width = 120;
var $height = 25;
var $min = 0;
var $max = 5;
var $value = 0;
var $border = 2;
var $bar_height = 10;
var $bar = 'blue_metalic.jpg';
var $palette = array();
var $textColor = 'black';
function ScaleJPG($value = 0) {
$this->createNewImage($value);
}
function createNewImage($value) {
$this->setValue($value);
$this->im = ImageCreate($this->width+1, $this->height+1);
$bgcolor = ImageColorAllocate ($this->im,
$this->bgcolor[0],
$this->bgcolor[1],
$this->bgcolor[2]);
}
function setValue($value) {
$this->value = $value;
}
function createImage() {
$this->createPalette();
$bar = ImageCreateFromJPEG($this->bar);
// Create the bar
ImageCopyMerge ($this->im,
$bar,
$this->border,
$this->height - $this->border - $this->bar_height,
0,0,
($this->width - 2 * $this->border) * ($this->value / $this->max), // width on scale
$this->bar_height,
100);
// Draw white rectangles every tick and their numbers
$tick_width = ($this->width - 2 * $this->border) / $this->max;
for($i = $this->border, $tick_count = $this->min;
$i <= $this->width - $this->border;
$i += $tick_width, $tick_count++) {
ImageFilledRectangle($this->im,
$i,
$this->height - $this->border - $this->bar_height,
$i,
$this->height - $this->border,
$this->palette['white']
);
ImageString($this->im,
1, // Font type
$i - $tick_width / 2,
$this->border,
$tick_count,
$this->palette[$this->textColor]
);
}
}
function getImage() {
$this->createImage();
return ImageJPEG($this->im);
}
function showImage() {
header ("Content-type: image/jpeg");
echo $this->getImage();
}
function createPalette() {
$this->palette['white'] = ImageColorAllocate($this->im, 255, 255, 255);
$this->palette['black'] = ImageColorAllocate($this->im, 0, 0, 0);
$this->palette['red'] = ImageColorAllocate($this->im, 255, 0, 0);
$this->palette['green'] = ImageColorAllocate($this->im, 0, 255, 0);
$this->palette['blue'] = ImageColorAllocate($this->im, 0, 0, 255);
}
function addColor($colorName, $red, $green, $blue) {
$this->palette[$colorName] = ImageColorAllocate($this->im, $red, $green, $blue);
}
}
?>
|