function createImage($text, $width, $height, $font = 5) { global $fontColor, $bgColor, $lineColor; if ($img = @ImageCreate($width, $height)) { list($R, $G, $B) = convertRGB($fontColor); $fontColor = ImageColorAllocate($img, $R, $G, $B); list($R, $G, $B) = convertRGB($bgColor); $bgColor = ImageColorAllocate($img, $R, $G, $B); list($R, $G, $B) = convertRGB($lineColor); $lineColor = ImageColorAllocate($img, $R, $G, $B); ImageFill($img, 0, 0, $bgColor); for ($i = 0; $i <= $width; $i += 5) { @ImageLine($img, $i, 0, $i, $height, $lineColor); } for ($i = 0; $i <= $height; $i += 5) { @ImageLine($img, 0, $i, $width, $i, $lineColor); } $hcenter = $width / 2; $vcenter = $height / 2; $x = round($hcenter - ImageFontWidth($font) * strlen($text) / 2); $y = round($vcenter - ImageFontHeight($font) / 2); ImageString($img, $font, $x, $y, $text, $fontColor); if (function_exists('ImagePNG')) { header('Content-Type: image/png'); @ImagePNG($img); } else { if (function_exists('ImageGIF')) { header('Content-Type: image/gif'); @ImageGIF($img); } else { if (function_exists('ImageJPEG')) { header('Content-Type: image/jpeg'); @ImageJPEG($img); } } } ImageDestroy($img); } }
function createImage($text, $width, $height, $font = 5) { global $fontColor, $bgColor, $lineColor, $set; if ($img = @ImageCreate($width, $height)) { list($R, $G, $B) = convertRGB($fontColor); $fontColor = ImageColorAllocate($img, $R, $G, $B); list($R, $G, $B) = convertRGB($bgColor); $bgColor = ImageColorAllocate($img, $R, $G, $B); list($R, $G, $B) = convertRGB($lineColor); $lineColor = ImageColorAllocate($img, $R, $G, $B); imagefilledrectangle($img, 0, 0, imagesx($img), imagesy($img), $bgColor); for ($i = 0; $i <= $width; $i += 5) { @ImageLine($img, $i, 0, $i, $height, $lineColor); } for ($i = 0; $i <= $height; $i += 5) { @ImageLine($img, 0, $i, $width, $i, $lineColor); } $hcenter = $width / 2; $vcenter = $height / 2; $x = round($hcenter - ImageFontWidth($font) * strlen($text) / 2); $y = round($vcenter - ImageFontHeight($font) / 2); ImageString($img, $font, $x, $y, $text, $fontColor); if (function_exists('ImagePNG')) { @ImagePNG($img, "data/catchpa.png"); return "png"; } else { if (function_exists('ImageGIF')) { @ImageGIF($img, "data/catchpa.gif"); return "gif"; } else { if (function_exists('ImageJPEG')) { @ImageJPEG($img, "data/catchpa.jpg"); return "jpg"; } } } ImageDestroy($img); } }