<?php
/*
1-9-2006 9:48
© De Bron Digital Solution (http://www.dbds.nl)
Ben Heesen (hide@address.com)
*/
class BMaker
{
function HexToRGB($color){
if (preg_match('/^#?[\\da-f]{6}$/i', $color)){
$color= preg_replace('/^#?([\\da-f]{6})$/i', '\\1', $color);
list($r,$g,$b)=BMaker::str_split($color,2);
$r=hexdec($r);
$g=hexdec($g);
$b=hexdec($b);
return array($r,$g,$b);
} else {
return false;
}
}
function text($text){
if($text == ''){
$this->text = 'sample';
}else{
$this->text = $text;
}
}
function font($font){
if($font == ''){
$this->font = 'fonts/arial.ttf';
}else{
$this->font = $font;
}
}
function fontsize($fontsize){
if($fontsize == ''){
$this->fontsize = 10;
}else{
$this->fontsize = $fontsize;
}
}
function textx($textx){
if($textx == ''){
$this->textx = 5;
}else{
$this->textx = $textx;
}
}
function texty($texty){
if($texty == ''){
$this->texty = 10;
}else{
$this->texty = $texty;
}
}
function bordertype($bordertype){
if($bordertype == ''){
unset($this->bordertype);
}else{
$this->bordertype = $bordertype;
}
}
function bgcolor($bgcolor){
if($bgcolor == ''){
$this->bgcolor = '#FFFFFF';
}else{
$this->bgcolor = $bgcolor;
}
}
function fgcolor($fgcolor){
if($fgcolor == ''){
$this->fgcolor = '#000000';
}else{
$this->fgcolor = $fgcolor;
}
}
function Buttonmaker($boxw,$boxh){
$this->box = imagettfbbox ($this->fsize, 0, $this->font, $this->text);
$textW = $this->box[2] - $this->box[0];
$textH= $this->box[3]- $this->box[5];
$paddingx = 10;
$paddingy = 10;
//Set image dimentions
$this->width = $boxw;
$this->height= $boxh;
if(!$textx){
$textx = ($this->width - $textW)/2;
}
if(!$texty){
$texty = ($this->height - $textH/2);
}
//convert background- & font-colors from hex to rgb
$bgcolor = BMaker::HexToRGB($this->bgcolor);
$fgcolor = BMaker::HexToRGB($this->fgcolor);
$this->img = imagecreatetruecolor($this->width,$this->height);
//Define Text (fg) and background (bg) colors
$BG = imagecolorallocate($this->img,$bgcolor[0],$bgcolor[1],$bgcolor[2]);
$FG = imagecolorallocate($this->img,$fgcolor[0],$fgcolor[1],$fgcolor[2]);
$this->bgcol = $BG;
$this->fgcol = $FG;
//Predefine some colors
$black = imagecolorallocate($this->img,0,0,0);
$lightgrey = imagecolorallocate($this->img,200,200,200);
$white = imagecolorallocate($this->img, 255, 255, 255);
$grey = imagecolorallocate($this->img, 152, 152, 152);
//fill image with background color
//gradient fill not available in lite version
imagefill($this->img,0,0,$this->bgcol);
//write shadow text
//not available in lite version
//Write Text
imagettftext($this->img, $this->fontsize, 0, $this->textx, $this->texty, $this->fgcol, $this->font, $this->text);
//Bordering
if ($this->bordertype == "out")
{
imageline ($this->img,0,0,$this->width,0,$white);
imageline ($this->img,0,0,0,$this->height,$white);
imageline ($this->img,1,1,$this->width,1,$lightgrey);
imageline ($this->img,1,1,1,$this->height-1,$lightgrey);
imageline ($this->img,0,$this->height-1,$this->width-1,$this->height-1,$black);
imageline ($this->img,$this->width-1,$this->height-1,$this->width-1,0,$black);
imageline ($this->img,2,$this->height-2,$this->width-2,$this->height-2,$grey);
imageline ($this->img,$this->width-2,$this->height-2,$this->width-2,2,$grey);
}
//Flat border
if ($this->bordertype == "flat")
{
imageline ($this->img,0,0,$this->width,0,$white);
imageline ($this->img,0,0,0,$this->height,$white);
imageline ($this->img,1,1,$this->width,1,$grey);
imageline ($this->img,1,1,1,$this->height-1,$grey);
imageline ($this->img,0,$this->height-1,$this->width-1,$this->height-1,$white);
imageline ($this->img,$this->width-1,$this->height-1,$this->width-1,0,$white);
imageline ($this->img,2,$this->height-2,$this->width-2,$this->height-2,$grey);
imageline ($this->img,$this->width-2,$this->height-2,$this->width-2,2,$grey);
}
//Engraved border (pushed button)
if ($this->bordertype == "in")
{
imageline ($this->img,0,0,$this->width,0,$black);
imageline ($this->img,0,0,0,$this->height,$black);
imageline ($this->img,1,1,$this->width,1,$grey);
imageline ($this->img,1,1,1,$this->height-1,$grey);
imageline ($this->img,0,$this->height-1,$this->width-1,$this->height-1,$white);
imageline ($this->img,$this->width-1,$this->height-1,$this->width-1,0,$white);
imageline ($this->img,2,$this->height-2,$this->width-2,$this->height-2,$lightgrey);
imageline ($this->img,$this->width-2,$this->height-2,$this->width-2,2,$lightgrey);
}
// ROTATION
// not available in line version
//show the image
BMaker::show();
}
//converting Hex colors to RGB colors
function str_split($string,$split_length=1){
$count = strlen($string);
if($split_length < 1){
return false;
} elseif($split_length > $count){
return array($string);
} else {
$num = (int)ceil($count/$split_length);
$ret = array();
for($i=0;$i<$num;$i++){
$ret[] = substr($string,$i*$split_length,$split_length);
}
}
return $ret;
}
//get imagetype
function format($type){
$this->format = $type;
}
//function show($img) {
function show() {
switch ($this->format) {
case "gif":
header("Content-type: image/gif");
imagegif($this->img);
imagedestroy($this->img);
break;
case "jpg":
header("Content-type: image/jpeg");
imagejpeg($this->img);
imagedestroy($this->img);
break;
case "png":
header("Content-type: image/png");
//Sends the image
imagepng($this->img);
imagedestroy($this->img);
break;
default:
header("Content-type: image/png");
//Sends the image
imagepng($this->img);
imagedestroy($this->img);
break;
}
return;
}
}//end class
?>