好久没上来发贴,呵呵,今天到Discuz论坛上看了一下,发现他的验证码做的不错,就下载下来研究了一下,好像是下载的跟他们本站的有点不同,不过差不多,大家可以到
http://www.discuz.net/register.php 这里看一下效果先。代码如下:
seccode.php
<?php
/*
[Discuz!] (C)2001-2007 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: seccode.php 9804 2007-08-15 05:56:19Z cnteacher $
*/
error_reporting(0);
set_magic_quotes_runtime(0);
session_start();
foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
foreach($$_request as $_key => $_value) {
$_key{0} != '_' && $$_key = daddslashes($_value);
}
}
$_DCACHE['settings'] = array (
'seccodedata' =>
array (
'minposts' => '',
'loginfailedcount' => 0,
'width' => 150,
'height' => 60,
'type' => '0',
'background' => '1',
'adulterate' => '1',
'ttf' => '0',
'angle' => '0',
'color' => '1',
'size' => '0',
'shadow' => '1',
'animator' => '1',
),
);
@extract($_DCACHE['settings']);
function daddslashes($string, $force = 0) {
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
if(!MAGIC_QUOTES_GPC || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
function dheader($string, $replace = true, $http_response_code = 0) {
$string = str_replace(array("\r", "\n"), array('', ''), $string);
if(empty($http_response_code) || PHP_VERSION < '4.3' ) {
@header($string, $replace);
} else {
@header($string, $replace, $http_response_code);
}
if(preg_match('/^\s*location:/is', $string)) {
exit();
}
}
function random($length, $numeric = 0) {
PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
} else {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
function seccodeconvert(&$seccode) {
global $seccodedata, $charset;
$seccode = substr($seccode, -6);
if($seccodedata['type'] == 1) {
$len = strtoupper($charset) == 'GBK' ? 2 : 3;
$code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
$seccode = '';
for($i = 0; $i < 2; $i++) {
$seccode .= substr($lang['chn'], $code[$i] * $len, $len);
}
} else {
$s = sprintf('%04s', base_convert($seccode, 10, 24));
$seccode = '';
$seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
for($i = 0; $i < 4; $i++) {
$unit = ord($s{$i});
$seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
}
}
}
$refererhost = parse_url($_SERVER['HTTP_REFERER']);
$refererhost['host'] .= !empty($refererhost['port']) ? (':'.$refererhost['port']) : '';
$seccodedata['width'] = $seccodedata['width'] >= 100 && $seccodedata['width'] <= 200 ? $seccodedata['width'] : 150;
$seccodedata['height'] = $seccodedata['height'] >= 50 && $seccodedata['height'] <= 80 ? $seccodedata['height'] : 60;
if($update) {
$seccode = random(6, 1) + $seccode{0} * 1000000;
}
seccodeconvert($seccode);
$_SESSION["seccode"] = $seccode;
if(!$nocacheheaders) {
@dheader("Expires: -1");
@dheader("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@dheader("Pragma: no-cache");
}
if($seccodedata['type'] < 2 && function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') &&
function_exists('imagecolorallocate') && function_exists('imagechar') && function_exists('imagecolorsforindex') &&
function_exists('imageline') && function_exists('imagecreatefromstring') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))) {
$bgcontent = seccode_background();
if($seccodedata['animator'] == 1 && function_exists('imagegif')) {
include_once './gifmerge.class.php';
$trueframe = mt_rand(1, 9);
for($i = 0; $i <= 9; $i++) {
$im = imagecreatefromstring($bgcontent);
$x[$i] = $y[$i] = 0;
$seccodedata['adulterate'] && seccode_adulterate();
if($i == $trueframe) {
$seccodedata['ttf'] && function_exists('imagettftext') || $seccodedata['type'] == 1 ? seccode_ttffont() : seccode_giffont();
$d[$i] = mt_rand(250, 400);
} else {
seccode_adulteratefont();
$d[$i] = mt_rand(5, 15);
}
ob_start();
imagegif($im);
imagedestroy($im);
$frame[$i] = ob_get_contents();
ob_end_clean();
}
$anim = new GifMerge($frame, 255, 255, 255, 0, $d, $x, $y, 'C_MEMORY');
dheader('Content-type: image/gif');
echo $anim->getAnimation();
} else {
$im = imagecreatefromstring($bgcontent);
$seccodedata['adulterate'] && seccode_adulterate();
$seccodedata['ttf'] && function_exists('imagettftext') || $seccodedata['type'] == 1 ? seccode_ttffont() : seccode_giffont();
if(function_exists('imagepng')) {
dheader('Content-type: image/png');
imagepng($im);
} else {
dheader('Content-type: image/jpeg');
imagejpeg($im, '', 100);
}
imagedestroy($im);
}
} elseif($seccodedata['type'] == 2 && extension_loaded('ming')) {
$spacing = 5;
$codewidth = ($seccodedata['width'] - $spacing * 5) / 4;
$strforswdaction = '';
for($i = 0; $i <= 3; $i++) {
$strforswdaction .= seccode_swfcode($codewidth, $spacing, $seccode[$i], $i+1);
}
ming_setScale(20.00000000);
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension($seccodedata['width'], $seccodedata['height']);
$movie->setBackground(255, 255, 255);
$movie->setRate(31);
$fontcolor = '0x'.(sprintf('%02s', dechex (mt_rand(0, 255)))).(sprintf('%02s', dechex (mt_rand(0, 128)))).(sprintf('%02s', dechex (mt_rand(0, 255))));
$strAction = "
_root.createEmptyMovieClip ( 'triangle', 1 );
with ( _root.triangle ) {
lineStyle( 3, $fontcolor, 100 );
$strforswdaction
}
";
$movie->add(new SWFAction( str_replace("\r", "", $strAction) ));
header('Content-type: application/x-shockwave-flash');
$movie->output();
} else {
$numbers = array
(
'B' => array('00','fc','66','66','66','7c','66','66','fc','00'),
'C' => array('00','38','64','c0','c0','c0','c4','64','3c','00'),
'E' => array('00','fe','62','62','68','78','6a','62','fe','00'),
'F' => array('00','f8','60','60','68','78','6a','62','fe','00'),
'G' => array('00','78','cc','cc','de','c0','c4','c4','7c','00'),
'H' => array('00','e7','66','66','66','7e','66','66','e7','00'),
'J' => array('00','f8','cc','cc','cc','0c','0c','0c','7f','00'),
'K' => array('00','f3','66','66','7c','78','6c','66','f7','00'),
'M' => array('00','f7','63','6b','6b','77','77','77','e3','00'),
'P' => array('00','f8','60','60','7c','66','66','66','fc','00'),
'Q' => array('00','78','cc','cc','cc','cc','cc','cc','78','00'),
'R' => array('00','f3','66','6c','7c','66','66','66','fc','00'),
'T' => array('00','78','30','30','30','30','b4','b4','fc','00'),
'V' => array('00','1c','1c','36','36','36','63','63','f7','00'),
'W' => array('00','36','36','36','77','7f','6b','63','f7','00'),
'X' => array('00','f7','66','3c','18','18','3c','66','ef','00'),
'Y' => array('00','7e','18','18','18','3c','24','66','ef','00'),
'2' => array('fc','c0','60','30','18','0c','cc','cc','78','00'),
'3' => array('78','8c','0c','0c','38','0c','0c','8c','78','00'),
'4' => array('00','3e','0c','fe','4c','6c','2c','3c','1c','1c'),
'6' => array('78','cc','cc','cc','ec','d8','c0','60','3c','00'),
'7' => array('30','30','38','18','18','18','1c','8c','fc','00'),
'8' => array('78','cc','cc','cc','78','cc','cc','cc','78','00'),
'9' => array('f0','18','0c','6c','dc','cc','cc','cc','78','00')
);
foreach($numbers as $i => $number) {
for($j = 0; $j < 6; $j++) {
$a1 = substr('012', mt_rand(0, 2), 1).substr('012345', mt_rand(0, 5), 1);
$a2 = substr('012345', mt_rand(0, 5), 1).substr('0123', mt_rand(0, 3), 1);
mt_rand(0, 1) == 1 ? array_push($numbers[$i], $a1) : array_unshift($numbers[$i], $a1);
mt_rand(0, 1) == 0 ? array_push($numbers[$i], $a1) : array_unshift($numbers[$i], $a2);
}
}
$bitmap = array();
for($i = 0; $i < 20; $i++) {
for($j = 0; $j < 4; $j++) {
$n = substr($seccode, $j, 1);
$bytes = $numbers[$n][$i];
$a = mt_rand(0, 14);
array_push($bitmap, $bytes);
}
}
for($i = 0; $i < 8; $i++) {
$a = substr('012345', mt_rand(0, 2), 1) . substr('012345', mt_rand(0, 5), 1);
array_unshift($bitmap, $a);
array_push($bitmap, $a);
}
$image = pack('H*', '424d9e000000000000003e000000280000002000000018000000010001000000'.
'0000600000000000000000000000000000000000000000000000FFFFFF00'.implode('', $bitmap));
dheader('Content-Type: image/bmp');
echo $image;
}
function seccode_background() {
global $seccodedata, $c;
$im = imagecreatetruecolor($seccodedata['width'], $seccodedata['height']);
$backgroundcolor = imagecolorallocate($im, 255, 255, 255);
$backgrounds = array();
if($seccodedata['background'] && function_exists('imagecreatefromjpeg') && function_exists('imagecolorat') && function_exists('imagecopymerge') &&
function_exists('imagesetpixel') && function_exists('imageSX') && function_exists('imageSY')) {
if($handle = @opendir('images/seccode/background/')) {
while($bgfile = @readdir($handle)) {
if(preg_match('/\.jpg$/i', $bgfile)) {
$backgrounds[] = 'images/seccode/background/'.$bgfile;
}
}
@closedir($handle);
}
if($backgrounds) {
$imwm = imagecreatefromjpeg($backgrounds[array_rand($backgrounds)]);
$colorindex = imagecolorat($imwm, 0, 0);
$c = imagecolorsforindex($imwm, $colorindex);
$colorindex = imagecolorat($imwm, 1, 0);
imagesetpixel($imwm, 0, 0, $colorindex);
$c[0] = $c['red'];$c[1] = $c['green'];$c[2] = $c['blue'];
imagecopymerge($im, $imwm, 0, 0, mt_rand(0, 200 - $seccodedata['width']), mt_rand(0, 80 - $seccodedata['height']), imageSX($imwm), imageSY($imwm), 100);
imagedestroy($imwm);
}
}
if(!$seccodedata['background'] || !$backgrounds) {
for($i = 0;$i < 3;$i++) {
$start[$i] = mt_rand(200, 255);$end[$i] = mt_rand(100, 150);$step[$i] = ($end[$i] - $start[$i]) / $seccodedata['width'];$c[$i] = $start[$i];
}
for($i = 0;$i < $seccodedata['width'];$i++) {
$color = imagecolorallocate($im, $c[0], $c[1], $c[2]);
imageline($im, $i, 0, $i-$angle, $seccodedata['height'], $color);
$c[0] += $step[0];$c[1] += $step[1];$c[2] += $step[2];
}
$c[0] -= 20;$c[1] -= 20;$c[2] -= 20;
}
ob_start();
if(function_exists('imagepng')) {
imagepng($im);
} else {
imagejpeg($im, '', 100);
}
imagedestroy($im);
$bgcontent = ob_get_contents();
ob_end_clean();
return $bgcontent;
}
function seccode_giffont() {
global $seccode, $seccodedata, $im, $c;
$seccodedir = array();
if(function_exists('imagecreatefromgif')) {
$seccoderoot = 'images/seccode/gif/';
$dirs = opendir($seccoderoot);
while($dir = readdir($dirs)) {
if($dir != '.' && $dir != '..' && file_exists($seccoderoot.$dir.'/9.gif')) {
$seccodedir[] = $dir;
}
}
}
$widthtotal = 0;
for($i = 0; $i <= 3; $i++) {
$imcodefile = $seccodedir ? $seccoderoot.$seccodedir[array_rand($seccodedir)].'/'.strtolower($seccode[$i]).'.gif' : '';
if(!empty($imcodefile) && file_exists($imcodefile)) {
$font[$i]['file'] = $imcodefile;
$font[$i]['data'] = getimagesize($imcodefile);
$font[$i]['width'] = $font[$i]['data'][0] + mt_rand(0, 6) - 4;
$font[$i]['height'] = $font[$i]['data'][1] + mt_rand(0, 6) - 4;
$font[$i]['width'] += mt_rand(0, $seccodedata['width'] / 5 - $font[$i]['width']);
$widthtotal += $font[$i]['width'];
} else {
$font[$i]['file'] = '';
$font[$i]['width'] = 8 + mt_rand(0, $seccodedata['width'] / 5 - 5);
$widthtotal += $font[$i]['width'];
}
}
$x = mt_rand(1, $seccodedata['width'] - $widthtotal);
for($i = 0; $i <= 3; $i++) {
$seccodedata['color'] && $c = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
if($font[$i]['file']) {
$imcode = imagecreatefromgif($font[$i]['file']);
if($seccodedata['size']) {
$font[$i]['width'] = mt_rand($font[$i]['width'] - $seccodedata['width'] / 20, $font[$i]['width'] + $seccodedata['width'] / 20);
$font[$i]['height'] = mt_rand($font[$i]['height'] - $seccodedata['width'] / 20, $font[$i]['height'] + $seccodedata['width'] / 20);
}
$y = mt_rand(0, $seccodedata['height'] - $font[$i]['height']);
if($seccodedata['shadow']) {
$imcodeshadow = $imcode;
imagecolorset($imcodeshadow, 0 , 255 - $c[0], 255 - $c[1], 255 - $c[2]);
imagecopyresized($im, $imcodeshadow, $x + 1, $y + 1, 0, 0, $font[$i]['width'], $font[$i]['height'], $font[$i]['data'][0], $font[$i]['data'][1]);
}
imagecolorset($imcode, 0 , $c[0], $c[1], $c[2]);
imagecopyresized($im, $imcode, $x, $y, 0, 0, $font[$i]['width'], $font[$i]['height'], $font[$i]['data'][0], $font[$i]['data'][1]);
} else {
$y = mt_rand(0, $seccodedata['height'] - 20);
if($seccodedata['shadow']) {
$text_shadowcolor = imagecolorallocate($im, 255 - $c[0], 255 - $c[1], 255 - $c[2]);
imagechar($im, 5, $x + 1, $y + 1, $seccode[$i], $text_shadowcolor);
}
$text_color = imagecolorallocate($im, $c[0], $c[1], $c[2]);
imagechar($im, 5, $x, $y, $seccode[$i], $text_color);
}
$x += $font[$i]['width'];
}
}
function seccode_ttffont() {
global $seccode, $seccodedata, $im, $c, $charset;
$seccoderoot = $seccodedata['type'] ? 'images/fonts/ch/' : 'images/fonts/en/';
$dirs = opendir($seccoderoot);
$seccodettf = array();
while($entry = readdir($dirs)) {
if($entry != '.' && $entry != '..' && strtolower(fileext($entry)) == 'ttf') {
$seccodettf[] = $entry;
}
}
$seccodelength = 4;
if($seccodedata['type'] && !empty($seccodettf)) {
if(strtoupper($charset) != 'UTF-8') {
include DISCUZ_ROOT.'include/chinese.class.php';
$cvt = new Chinese($charset, 'utf8');
$seccode = $cvt->Convert($seccode);
}
$seccode = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
$seccodelength = 2;
}
$widthtotal = 0;
for($i = 0; $i < $seccodelength; $i++) {
$font[$i]['font'] = $seccoderoot.$seccodettf[array_rand($seccodettf)];
$font[$i]['angle'] = $seccodedata['angle'] ? mt_rand(-30, 30) : 0;
$font[$i]['size'] = $seccodedata['type'] ? $seccodedata['width'] / 7 : $seccodedata['width'] / 6;
$seccodedata['size'] && $font[$i]['size'] = mt_rand($font[$i]['size'] - $seccodedata['width'] / 40, $font[$i]['size'] + $seccodedata['width'] / 20);
$box = imagettfbbox($font[$i]['size'], 0, $font[$i]['font'], $seccode[$i]);
$font[$i]['zheight'] = max($box[1], $box[3]) - min($box[5], $box[7]);
$box = imagettfbbox($font[$i]['size'], $font[$i]['angle'], $font[$i]['font'], $seccode[$i]);
$font[$i]['height'] = max($box[1], $box[3]) - min($box[5], $box[7]);
$font[$i]['hd'] = $font[$i]['height'] - $font[$i]['zheight'];
$font[$i]['width'] = (max($box[2], $box[4]) - min($box[0], $box[6])) + mt_rand(0, $seccodedata['width'] / 8);
$font[$i]['width'] = $font[$i]['width'] > $seccodedata['width'] / $seccodelength ? $seccodedata['width'] / $seccodelength : $font[$i]['width'];
$widthtotal += $font[$i]['width'];
}
$x = mt_rand($font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $seccodedata['width'] - $widthtotal);
!$seccodedata['color'] && $text_color = imagecolorallocate($im, $c[0], $c[1], $c[2]);
for($i = 0; $i < $seccodelength; $i++) {
if($seccodedata['color']) {
$c = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$seccodedata['shadow'] && $text_shadowcolor = imagecolorallocate($im, 255 - $c[0], 255 - $c[1], 255 - $c[2]);
$text_color = imagecolorallocate($im, $c[0], $c[1], $c[2]);
} elseif($seccodedata['shadow']) {
$text_shadowcolor = imagecolorallocate($im, 255 - $c[0], 255 - $c[1], 255 - $c[2]);
}
$y = $font[0]['angle'] > 0 ? mt_rand($font[$i]['height'], $seccodedata['height']) : mt_rand($font[$i]['height'] - $font[$i]['hd'], $seccodedata['height'] - $font[$i]['hd']);
$seccodedata['shadow'] && imagettftext($im, $font[$i]['size'], $font[$i]['angle'], $x + 1, $y + 1, $text_shadowcolor, $font[$i]['font'], $seccode[$i]);
imagettftext($im, $font[$i]['size'], $font[$i]['angle'], $x, $y, $text_color, $font[$i]['font'], $seccode[$i]);
$x += $font[$i]['width'];
}
}
function seccode_adulterate() {
global $seccodedata, $im, $c;
$linenums = $seccodedata['height'] / 10;
for($i=0; $i <= $linenums; $i++) {
$color = $seccodedata['color'] ? imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)) : imagecolorallocate($im, $c[0], $c[1], $c[2]);
$x = mt_rand(0, $seccodedata['width']);
$y = mt_rand(0, $seccodedata['height']);
if(mt_rand(0, 1)) {
imagearc($im, $x, $y, mt_rand(0, $seccodedata['width']), mt_rand(0, $seccodedata['height']), mt_rand(0, 360), mt_rand(0, 360), $color);
} else {
imageline($im, $x, $y, $linex + mt_rand(0, $linemaxlong), $liney + mt_rand(0, mt_rand($seccodedata['height'], $seccodedata['width'])), $color);
}
}
}
function seccode_adulteratefont() {
global $seccodedata, $im, $c;
$seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
$x = $seccodedata['width'] / 4;
$y = $seccodedata['height'] / 10;
$text_color = imagecolorallocate($im, $c[0], $c[1], $c[2]);
for($i = 0; $i <= 3; $i++) {
$adulteratecode = $seccodeunits[mt_rand(0, 23)];
imagechar($im, 5, $x * $i + mt_rand(0, $x - 10), mt_rand($y, $seccodedata['height'] - 10 - $y), $adulteratecode, $text_color);
}
}
function seccode_swfcode($width, $d, $code, $order) {
global $seccodedata;
$str = '';
$height = $seccodedata['height'] - $d * 2;
$x_0 = ($order * ($width + $d) - $width);
$x_1 = $x_0 + $width / 2;
$x_2 = $x_0 + $width;
$y_0 = $d;
$y_2 = $y_0 + $height;
$y_1 = $y_2 / 2;
$y_0_5 = $y_2 / 4;
$y_1_5 = $y_1 + $y_0_5;
switch($code) {
case 'B':$str .= 'moveTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_1.', '.$y_2.');lineTo('.$x_2.', '.$y_1_5.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'C':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');';break;
case 'E':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'F':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'G':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'H':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case 'J':$str .= 'moveTo('.$x_1.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_1_5.');';break;
case 'K':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');';break;
case 'M':$str .= 'moveTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');';break;
case 'P':$str .= 'moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');';break;
case 'Q':$str .= 'moveTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_1.', '.$y_1.');';break;
case 'R':$str .= 'moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');';break;
case 'T':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');moveTo('.$x_1.', '.$y_0.');lineTo('.$x_1.', '.$y_2.');';break;
case 'V':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');';break;
case 'W':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');';break;
case 'X':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');';break;
case 'Y':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_1.', '.$y_2.');';break;
case '2':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');';break;
case '3':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case '4':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case '6':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');';break;
case '7':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');';break;
case '8':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case '9':$str .= 'moveTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');';break;
}
return $str;
}
?> ;
gifmerge.class.php
<?php
class GifMerge {
var $ver = '1.1';
var $dly = 50;
var $mod = 'C_FILE';
var $first = true;
var $use_loop = false;
var $transparent = false;
var $use_global_in = false;
var $x = 0;
var $y = 0;
var $ch = 0;
var $fin = 0;
var $fout = '';
var $loop = 0;
var $delay = 0;
var $width = 0;
var $height = 0;
var $trans1 = 255;
var $trans2 = 255;
var $trans3 = 255;
var $disposal = 2;
var $out_color_table_size = 0;
var $local_color_table_flag = 0;
var $global_color_table_size = 0;
var $out_color_table_sizecode = 0;
var $global_color_table_sizecode= 0;
var $gif = array(0x47, 0x49, 0x46);
var $buffer = array();
var $local_in = array();
var $global_in = array();
var $global_out = array();
var $logical_screen_descriptor = array();
function GifMerge($images, $t1, $t2, $t3, $loop, $dl, $xpos, $ypos, $model) {
if($model) {
$this->mod = $model;
}
if($loop > -1) {
$this->loop = floor($loop - 1);
$this->use_loop = true;
}
if($t1 > -1 && $t2 > -1 && $t3 > -1) {
$this->trans1 = $t1;
$this->trans2 = $t2;
$this->trans3 = $t3;
$this->transparent = true;
}
for($i = 0; $i < count($images); $i++) {
$dl[$i] ? $this->delay = $dl[$i] : $this->delay = $this->dly;
$xpos[$i] ? $this->x = $xpos[$i] : $this->x = 0;
$ypos[$i] ? $this->y = $ypos[$i] : $this->y = 0;
$this->start_gifmerge_process($images[$i]);
}
$this->fout .= "\x3b";
}
function start_gifmerge_process($fp) {
if($this->mod == 'C_FILE') {
if(!$this->fin = fopen($fp, 'rb')) {
return;
}
} elseif($this->mod == 'C_MEMORY') {
$this->ch = 0;
$this->fin = $fp;
}
$this->getbytes(6);
if(!$this->arrcmp($this->buffer, $this->gif, 3)) {
return;
}
$this->getbytes(7);
if($this->first) $this->logical_screen_descriptor = $this->buffer;
$this->global_color_table_sizecode = $this->buffer[4] & 0x07;
$this->global_color_table_size = 2 << $this->global_color_table_sizecode;
if($this->buffer[4] & 0x80) {
$this->getbytes((3 * $this->global_color_table_size));
for($i = 0; $i < ((3 * $this->global_color_table_size)); $i++) {
$this->global_in[$i] = $this->buffer[$i];
}
if($this->out_color_table_size == 0) {
$this->out_color_table_size = $this->global_color_table_size;
$out_color_table_sizecode = $this->global_color_table_sizecode;
$this->global_out = $this->global_in;
}
if($this->global_color_table_size != $this->out_color_table_size || $this->arrcmp($this->global_out, $this->global_in, (3 * $this->global_color_table_size))) {
$this->use_global_in = true;
}
}
for($loop = true; $loop;) {
$this->getbytes(1);
switch($this->buffer[0]) {
case 0x21:
$this->read_extension();
break;
case 0x2c:
$this->read_image_descriptor();
break;
case 0x3b:
$loop = false;
break;
default:
$loop = false;
}
}
if($this->mod == 'C_FILE') {
fclose($this->fin);
}
}
function read_image_descriptor() {
$this->getbytes(9);
$head = $this->buffer;
$this->local_color_table_flag = ($this->buffer[8] & 0x80) ? true : false;
if($this->local_color_table_flag) {
$sizecode = $this->buffer[8] & 0x07;
$size = 2 << $sizecode;
$this->getbytes(3 * $size);
for($i = 0; $i < (3 * $size); $i++) {
$this->local_in[$i] = $this->buffer[$i];
}
if($this->out_color_table_size == 0) {
$this->out_color_table_size = $size;
$out_color_table_sizecode = $sizecode;
for($i = 0; $i < (3 * $size); $i++)
{
$this->global_out[$i] = $this->local_in[$i];
}
}
}
if($this->first) {
$this->first = false;
$this->fout .= "\x47\x49\x46\x38\x39\x61";
if($this->width && $this->height) {
$this->logical_screen_descriptor[0] = $this->width & 0xFF;
$this->logical_screen_descriptor[1] = ($this->width & 0xFF00) >> 8;
$this->logical_screen_descriptor[2] = $this->height & 0xFF;
$this->logical_screen_descriptor[3] = ($this->height & 0xFF00) >> 8;
}
$this->logical_screen_descriptor[4] |= 0x80;
$this->logical_screen_descriptor[5] &= 0xF0;
$this->logical_screen_descriptor[6] |= $this->out_color_table_sizecode;
$this->putbytes($this->logical_screen_descriptor, 7);
$this->putbytes($this->global_out, ($this->out_color_table_size * 3));
if($this->use_loop) {
$ns[0] = 0x21;
$ns[1] = 0xFF;
$ns[2] = 0x0B;
$ns[3] = 0x4e;
$ns[4] = 0x45;
$ns[5] = 0x54;
$ns[6] = 0x53;
$ns[7] = 0x43;
$ns[8] = 0x41;
$ns[9] = 0x50;
$ns[10] = 0x45;
$ns[11] = 0x32;
$ns[12] = 0x2e;
$ns[13] = 0x30;
$ns[14] = 0x03;
$ns[15] = 0x01;
$ns[16] = $this->loop & 255;
$ns[17] = $this->loop >> 8;
$ns[18] = 0x00;
$this->putbytes($ns, 19);
}
}
if($this->use_global_in) {
$outtable = $this->global_in;
$outsize = $this->global_color_table_size;
$outsizecode = $this->global_color_table_sizecode;
} else {
$outtable = $this->global_out;
$outsize = $this->out_color_table_size;
}
if($this->local_color_table_flag) {
if($size == $this->out_color_table_size && !$this->arrcmp($this->local_in, $this->global_out, $size)) {
$outtable = $global_out;
$outsize = $this->out_color_table_size;
} else {
$outtable = $this->local_in;
$outsize = $size;
$outsizecode = $sizecode;
}
}
$use_trans = false;
if($this->transparent) {
for($i = 0; $i < $outsize; $i++) {
if($outtable[3 * $i] == $this->trans1 && $outtable [3 * $i + 1] == $this->trans2 && $outtable [3 * $i + 2] == $this->trans3) {
break;
}
}
if($i < $outsize) {
$transindex = $i;
$use_trans = true;
}
}
if($this->delay || $use_trans) {
$this->buffer[0] = 0x21;
$this->buffer[1] = 0xf9;
$this->buffer[2] = 0x04;
$this->buffer[3] = ($this->disposal << 2) + ($use_trans ? 1 : 0);
$this->buffer[4] = $this->delay & 0xff;
$this->buffer[5] = ($this->delay & 0xff00) >> 8;
$this->buffer[6] = $use_trans ? $transindex : 0;
$this->buffer[7] = 0x00;
$this->putbytes($this->buffer,8);
}
$this->buffer[0] = 0x2c;
$this->putbytes($this->buffer,1);
$head[0] = $this->x & 0xff;
$head[1] = ($this->x & 0xff00) >> 8;
$head[2] = $this->y & 0xff;
$head[3] = ($this->y & 0xff00) >> 8;
$head[8] &= 0x40;
if($outtable != $this->global_out) {
$head[8] |= 0x80;
$head[8] |= $outsizecode;
}
$this->putbytes($head,9);
if($outtable != $this->global_out) {
$this->putbytes($outtable, (3 * $outsize));
}
$this->getbytes(1);
$this->putbytes($this->buffer,1);
for(;;) {
$this->getbytes(1);
$this->putbytes($this->buffer,1);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
$this->putbytes($this->buffer, $u);
}
}
function read_extension() {
$this->getbytes(1);
switch($this->buffer[0]) {
case 0xf9:
$this->getbytes(6);
break;
case 0xfe:
for(;;) {
$this->getbytes(1);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
}
break;
case 0x01:
$this->getbytes(13);
for(;;) {
$this->getbytes(0);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
}
break;
case 0xff:
$this->getbytes(9);
$this->getbytes(3);
for(;;) {
$this->getbytes(1);
if(!$this->buffer[0]) {
break;
}
$this->getbytes($this->buffer[0]);
}
break;
default:
for(;;) {
$this->getbytes(1);
if(!$this->buffer[0]) {
break;
}
$this->getbytes($this->buffer[0]);
}
}
}
function arrcmp($b, $s, $l) {
for($i = 0; $i < $l; $i++) {
if($s{$i} != $b{$i}) {
return false;
}
}
return true;
}
function getbytes($l) {
for($i = 0; $i < $l; $i++) {
if($this->mod == 'C_FILE') {
$bin = unpack('C*', fread($this->fin, 1));
$this->buffer[$i] = $bin[1];
} elseif($this->mod == 'C_MEMORY') {
$bin = unpack('C*', substr($this->fin, $this->ch, 1));
$this->buffer[$i] = $bin[1];
$this->ch++;
}
}
return $this->buffer;
}
function putbytes($s, $l) {
for($i = 0; $i < $l; $i++) {
$this->fout .= pack('C*', $s[$i]);
}
}
function getAnimation() {
return $this->fout;
}
}
?> ;
用法:
<img src="seccode.php?update=0.11426983225638004" width="160" height="60" onclick="this.src='seccode_1.php?update=0.11426983225638004'"/>
下载:
seccode.rar (99.52 KB)
呵呵,粗略的搞下来了,有不妥的地方大家自己改改吧,改好了不要忘记传上来大家一起用,省得浪费其它人的时间嘛,呵。