Mehdi Posted November 1, 2006 Share Posted November 1, 2006 Hi,The below script doesn't run. If I run it I get the error message of "The image cannot be displayed".Could you tell me where the error is?[code]<?phpheader("Content-type: image/png");class simpelbar{ private $margin=20; private $marginverticalline=20; private $marginhorizentalline=40; private $barmargin=10; private $inputwidth; private $inputheight; private $cells=array(); private $font="luxisri.ttf"; function __construct($width,$height){ $this->inputwidth=$width; $this->inputheight=$height; } function aadbar($company,$money){ $this->cells[$company]=$money; } private function fontadjust($widthbar){ $fontsize=$this->marginhorizentalline; foreach($this->cells as $key=>$val){ while(true){ $textsize=imageTTFbbox($fontsize,0,$this->font,$key); if(abs($textsize[2])<$widthbar){ break; } $fontsize--; } } return $fontsize; } function draw(){ $realwidth=$this->inputwidth-$this->margin*2; $realheight=$this->inputheight-$this->margin*2; $ystarthorizentalline=$realheight-$this->marginhorizentalline; $xendhorizentalline=$realwidth-$this->margin; $max=max($this->cells); $totalbars=count($this->cells); $verticallinelong=$ystarthorizentalline-$this->margin; $widthbar=(int)($realwidth-(2*$this->margin)-($this-barmargin*($totalbars+1))/$totalbars); $text_size=$this->fontadjust($widthbar); $image=imagecreate($realwidth,$realheight); $red=imagecolorallocate($image,255,0,0); $blue=imagecolorallocate($image,0,0,255); $black=imagecolorallocate($image,0,0,0); imageline($image, $this->margin,$ystartborizentalline,$this->margin,$this->margin,$black); imageline($image,$this->margin,$ystarthorizentalline,$xendhorizentalline,$ystarthorizentalline,$black); $xbar=$this->margin+$this->barmargin; foreach($this->cells as $key=>$val){ $ybar=$ystarthorizentalline-(int)(($val/$max)*$verticallinelong); $nextxbar=$xbar+$widthbar; $nextybar=$this->marginhorizentalline; imagefilledrectangle($image,$xbar,$ybar,$nextxbar,$nextybar,$blue); $box=imageTTFbbox($text_size,0,$this->font,$key); $xstartfont=$xbar+(int)(($widthbar-$box[2])/2); imageTTFtext($image,35,0,$xstartfont,$realheight-5,$black,$this->font,$key); $xbar=$nextxbar+$this->barmargin; } imagepng($image); }}$test=new simpelbar(400,300);$test->addbar("Shell",300);$test->addbar("Philips",200);$test->addbar("CCC",400);$test->draw();?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25785-imagepng-problem/ Share on other sites More sharing options...
HuggieBear Posted November 1, 2006 Share Posted November 1, 2006 The function in your class is called aadbar (notice the two 'a') and you call is using addbar (notice the two 'd').RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25785-imagepng-problem/#findComment-117738 Share on other sites More sharing options...
Mehdi Posted November 1, 2006 Author Share Posted November 1, 2006 [quote author=HuggieBear link=topic=113440.msg460993#msg460993 date=1162372581]The function in your class is called aadbar (notice the two 'a') and you call is using addbar (notice the two 'd').RegardsHuggie[/quote]Thanks Quote Link to comment https://forums.phpfreaks.com/topic/25785-imagepng-problem/#findComment-117740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.