public function draw(){
/*
* to draw Image of the captcha code
*/
if ($this->BackgroundImage === null){
if ($this->Color_B === null || $this->Color_B === null || $this->Color_B === null ){
if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null)
$this->SetTextColor(0, 0, 0);
//if obj doen't have background image,background color and text color,it will be set as 0, 0, 0
} else {
if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null){
$this->RGB2HSL();
$this->HSL2RGB();
//if obj doesn't have backgorund image,but have background color,and dont have textcolor,it will be set by XPart:D
}
}
} else {
if ($this->Color_B === null || $this->Color_B === null || $this->Color_B === null ){
$this->getImageMainRGB(); // if obj doesn't background Image,but dont have background color,it will be set by this method
if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null){
$this->RGB2HSL();
$this->HSL2RGB();
//if obj doesn't have TextColor ,it will be set by XPart:D
}
} else {
if ($this->TC_B === null || $this->TC_B === null || $this->TC_B === null){
$this->RGB2HSL();
$this->HSL2RGB();
//XPart again,if TextColor doesnt set,but Background color set
}
}
}
// End of Set Background and Text Color
$this->setFontCanBeUseSRC();//make random font
if ($this->BackgroundImage != null){//have background
//create image
switch ($this->ImageSuffix){
case 'gif':
$im = imagecreatefromgif($this->BackgroundImage);
break;
case 'jpg':
$im = imagecreatefromjpeg($this->BackgroundImage);
break;
case 'png':
default:
$im = imagecreatefrompng($this->BackgroundImage);
}
$this->width = imagesx($im);
$this->height= imagesy($im);
} else { //dont have background
$im = imagecreatetruecolor($this->width, $this->height);
if (!($this->Color_R === null || $this->Color_G === null || $this->Color_B === null)){
$color_Back = imagecolorallocate($im, $this->Color_R , $this->Color_G, $this->Color_B);
imagefilledrectangle($im, 0, 0, $this->width, $this->height, $color_Back);
} else {
//with out background (transparnet image)
imagealphablending($im, false);
$col=imagecolorallocatealpha($im,255,255,255,127);
//Create overlapping 100x50 transparent layer
imagefilledrectangle($im,0,0,$this->width, $this->height,$col);
//Continue to keep layers transparent
imagealphablending($im,true);
}
}
$color_Text = imagecolorallocate($im, $this->TC_R , $this->TC_G, $this->TC_B);//make text color by RGB
$count = strlen($this->Text);
$XSize = ($this->width / $count + 5);
for ($i = 0; $i < $count; $i++){
$char = substr($this->Text,$i,1);
$font = $this->getFontSRC();
$angle = $this->randangle();
$array = $this->getFontSize_Position($font, $char, $angle, $XSize);
imagefttext($im, $array['size'], $angle, $i * ($XSize - 5) + 5, $array['YPos'], $color_Text,$font, $char);
//draw a char into image
}
switch ($this->ImageSuffix){
//send header and draw image
case 'jpg':
header('Content-type: image/jpeg');
imagejpeg($im);
break;
case 'gif':
header('Content-type: image/gif');
imagegif($im);
break;
case 'png':
header('Content-type: image/png');
imagepng($im);
break;
default:
imagesavealpha($im,true);
imagepng($im,"MoeinCaptchaTranspartImage.png",1);
header("Content-Type: image/png");
readfile("MoeinCaptchaTranspartImage.png");
break;
}
//release a memory