Hi all,
I tried to create a dynamic button using PHP and I'm getting the following warning.
imagejpeg(): supplied argument is not a valid Image resource.
The code I've written is
<?php
class Button
{
private $image;
public function construct($width,$label,$font)
{
$this->image=imagecreate($width,$height);
$colorbody=imagecolorallocate($this->image,099,099,099);
$colorshadow=imagecolorallocate($this->image,033,033,033);
$colorHighlight=imagecolorallocate($this->image,0CC,0CC,0CC);
//create body of the button
imagefilledrectangle($this->image,1,1,$width-2,$height-2,$colorbody);
//draw bottom shadow
imageline($this->image,0,$height-1,$width-1,$height-1,$colorshadow);
//draw right shadow
imageline($this->image,$width-1,1,$width-1,$height-1,$colorshadow);
//draw top highlight
imageline($this->image,0,0,$width-1,0,$colorHighlight);
//draw left highlight
imageline($this->image,0,0,0,$height-2,$colorHighlight);
//determine label size
$labelheight=imagefontheight($font);
$labelwidth=imagefontwidth($font)strlen($label);
//determine label upper left corner
$labelX=($width-$labelwidth)/2;
$labelY=($height-$labelheight)/2;
//draw label shadow
imagestring($this->image,$font,$labelX+1,$labelY+1,$label,$colorshadow);
//draw label
imagestring($this->image,$font,$labelX+1,$labelY+1,$label,$colorhighlight);
}
public function drawPNG() {
header("Content-type:image/png");
imagepng($this->image);
}
public function drawJPEG() {
header("Content-type:image/jpeg");
imagejpeg($this->image);
}
}
//set parameters if not given
if(!isset($REQUEST['width']))
{
$REQUEST['width']=100;
}
if(!isset($REQUEST['height']))
{
$REQUEST['height']=30;
}
if(!isset($REQUEST['label']))
{
$REQUEST['label']="click";
}
if(!isset($REQUEST['font']))
{
$REQUEST['font']=5;
}
$b=new Button($REQUEST['width'],$REQUEST['height'],$REQUEST['label'],$REQUEST['font']);
$b->drawPNG();
?>
I'm unable to find the mistake in my code. can anybody help me?
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).