function Create() { $this->code = GenerateCode(); list($this->image_width, $this->image_height) = $this->CalculateImageDimensions($this->code); // Create the image $this->image = imagecreatetruecolor($this->image_width, $this->image_height); // Fill the background with a gradient list($this->bg_dark, $this->bg_light) = FillBackground($this->image); // Add the code to the image $this->AddText(); }
for ($i = 0; $i < strlen($str); $i++) { $ang = rand(-20, 20); $sz = $f_sz + rand(-4, 4); ImageTTFText($imgf, $sz - rand(2, 4), $ang, $x + rand(-5, 5), $y + rand(-5, 5), AddColors(0x404040, RandomColor(0, 100)), $f_name, $str[$i]); ImageTTFText($imgf, $sz, $ang, $x, $y, RandomColor(0, 128), $f_name, $str[$i]); $arr = ImageTTFBBox($f_sz, 0, $f_name, $str[$i]); $x += $arr[4] - $arr[0] + $spc; } GenerateNoise($imgf, $wdt, $hgt, 10, 10, false); return $imgf; } function GenerateCode($len) { $gs = "2345689ABCDEFHIKLMNPQRSTUVWXYZ"; $str = ""; for ($i = 0; $i < $len; $i++) { $str .= $gs[rand(0, strlen($gs) - 1)]; } return array("0" => GeneratePicture($str), "1" => $str); } function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } session_start(); $arr = GenerateCode(8); $_SESSION["secret_code"] = $arr[1]; header("Content-type: image/jpeg"); ImageJPEG($arr[0], '', 50); ImageDestroy($arr[0]);