免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1349 | 回复: 3
打印 上一主题 下一主题

生成图像的程序,在win下好用,linux下为什么成了x? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-19 16:16 |只看该作者 |倒序浏览
linux系统为fedora core 3

图片是这样的:现存一个jpg,然后在上面加上随机的几个字符,图片的链接还是php.

-----------------------------------------------------------------------------------
某页面图片链接<img src="SecuImage.php">;

-----------------------------------------------
SecuImage.php文件

<?
include("securityImageClass.php";

$si = new securityImage();

$si->;showImage();

?>;

-----------------------------------------------
securityImageClass.php文件

<?
class securityImage {

var $inputParam = "";                        // Public;
var $name         = "security";                // Public;
var $codeLength = 5;                        // Private;
var $fontSize        = 6;                        // Private;
var $fontColor  = "000000";                // Private;  FFFFFF白色  000000黑色
var $imageFile  = "map.jpg";        // Private;   MUST BE JPEG FILE!

var $securityCode = "";                        // Private

function securityImage()
{
        session_start();
}       

function simpleRandString($length=16, $list="23456789ABCDEFGHIJKMNPRSTUVWXYZ"
{
        /*
         * Generates a random string with the specified length
         * Chars are chosen from the provided [optional] list
        */
        mt_srand((double)microtime()*1000000);

        $newstring = "";

        if ($length >; 0) {
                while (strlen($newstring) < $length) {
                        $newstring .= $list[mt_rand(0, strlen($list)-1)];
                }
        }
        return $newstring;
}

function showImage() {
        header("Content-type: image/jpeg";
        $this->;generateImage();
        imagejpeg($this->;img);
        imageDestroy($this->;img);
}


function generateImage() {

        $this->;securityCode = $this->;simpleRandString($this->;codeLength);

        $_SESSION['security_code'] = $this->;securityCode;

        $img_path = dirname(__FILE__)."/$this->;imageFile";

        $this->;img = ImageCreateFromJpeg($img_path);

        $img_size = getimagesize($img_path);

        $color = imagecolorallocate($this->;img,
                        hexdec(substr($this->;fontColor, 1, 2)),
                        hexdec(substr($this->;fontColor, 3, 2)),
                        hexdec(substr($this->;fontColor, 5, 2))
                        );

        $fw = imagefontwidth($this->;fontSize);
        $fh = imagefontheight($this->;fontSize);

        // create a new string with a blank space between each letter so it looks better
        $newstr = "";
        for ($i = 0; $i < strlen($this->;securityCode); $i++) {
                $newstr .= $this->;securityCode[$i] ." ";
        }
       
        // remove the trailing blank
        $newstr = trim($newstr);

        // center the string
        $x = ($img_size[0] - strlen($newstr) * $fw ) / 2;

        // output each character at a random height and standard horizontal spacing
        for ($i = 0; $i < strlen($newstr); $i++) {
                $hz = mt_rand( 10, $img_size[1] - $fh - 5);
                imagechar( $this->;img, $this->;fontSize, $x + ($fw*$i), $hz, $newstr[$i], $color);
        }
}


}
?>;

论坛徽章:
0
2 [报告]
发表于 2005-05-19 16:24 |只看该作者

生成图像的程序,在win下好用,linux下为什么成了x?

跟这有关系吗?fc里看的

论坛徽章:
0
3 [报告]
发表于 2005-05-19 21:40 |只看该作者

生成图像的程序,在win下好用,linux下为什么成了x?

linux系统下有没有装gd库

论坛徽章:
0
4 [报告]
发表于 2005-05-20 03:31 |只看该作者

生成图像的程序,在win下好用,linux下为什么成了x?

高手,一语道破啊

thanks!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP