8.PHP图像处理

PHP图像处理

GD2


Jpgraph


创建一个画布:

<?php
    header('content-type:image/gif');
    //echo "你好";
    $im = imagecreate(200,60);
    $white = imagecolorallocate($im ,225 ,66 ,159);
    imagegif($im);
?>


显示一张图片

<?php
        function LoadPNG($imgname)
        {
            /* Attempt to open */
            $im = @imagecreatefromjpeg($imgname);
            /* See if it failed */
            if(!$im){
                echo "aaa";
                /* Create a blank image */
                $im  = imagecreatetruecolor(150,40);
                $bgc = imagecolorallocate($im255255255);
                $tc  = imagecolorallocate($im000);
                imagefilledrectangle($im0015040$bgc);
                /* Output an error message */
                imagestring($im155'bb ' $imgname$tc);
            }
            return $im;
        }

        header('Content-Type: image/jpeg');
        $img = LoadPNG('p.jpg');
        imagepng($img);
        imagedestroy($img);
?>


随机生成验证码:

<?php
    session_start();
    header('Content-Type: image/png');
    $image_width 70;
    $image_height 18;
    srand(microtime()*100000);
    $new_number '';
    for($i ;$i ;$i ++){
        $new_number.=dechex(rand(,15));
    }
    $_SESSION['check_checks'] = $new_number;
    $num_image = imagecreate($image_width ,$image_height);
    imagecolorallocate($num_image ,255 ,255 ,255);
    for($i ;$i < strlen($_SESSION['check_checks']) ;$i ++){
        $font = mt_rand(,5);
        $x = mt_rand(,8) + $image_width $i 4;
        $y = mt_rand(,$image_height 4);
        $color imagecolorallocate($num_image ,mt_rand(0,100,mt_rand(,150,mt_rand(,200));
        imagestring($num_image ,$font ,$x ,$y,$_SESSION['check_checks'][$i,$color);
    }
    imagepng($num_image);
    imagedestroy($num_image);
?>


创建一个柱形图

<?php
    include ("src/jpgraph.php");
    include ("src/jpgraph_bar.php");
    $datay array(160 ,180 ,203 ,289 ,405 ,488 ,489 ,408 ,299 ,166 ,187 ,205);
    $graph new Graph(600 ,300 ,"auto");
    $graph -> SetScale("textlin");
    $graph -> yaxis -> scale -> SetGrace(20);
    $graph -> SetShadow();
    $graph -> img -> SetMargin(40 ,30 ,30 ,40);
    $bplot new BarPlot($datay);
    $bplot -> SetFillColor('orange');
    $bplot -> value -> Show();
    $bplot -> value -> SetFormat('%d');
    $graph -> Add($bplot);
    $graph -> SetMarginColor("lightblue");
    $graph -> title -> Set("tit");
    $a array(,,,,,,,,,10 ,11 ,12);
    $graph -> xaxis -> SetTickLabels($a);
    $graph -> title -> SetFont(FF_SIMSUN);
    $graph -> xaxis -> SetFont(FF_SIMSUN);
    $graph -> Stroke();
?>


绘制折线图

<?php
    include ("src/jpgraph.php");
    include ("src/jpgraph_line.php");
    $datay array(160 ,180 ,203 ,289 ,405 ,488 ,489 ,408 ,299 ,166 ,187 ,500);
    $graph new Graph(600 ,300 ,"auto");
    $graph -> img -> SetMargin(50 ,40 ,30 ,40);
    $graph -> img -> SetAntiAliasing();
    $graph -> SetScale("textlin");
    $graph -> SetShadow();
    $graph -> title -> Set("tit");
    $graph -> title -> SetFont(FF_SIMSUN ,FS_BOLD);
    $graph -> SetMarginColor("lightblue");
    $graph -> yaxis ->title -> SetFont(FF_SIMSUN);
    $graph -> xaxis -> SetPos("min");
    $graph -> yaxis -> HideZeroLabel();
    $graph -> ygrid -> SetFill(true ,'#EFEFEF@0.5' ,'#BBCCFF@0.5');


    $a array(,,,,,,,,,10 ,11 ,12);
    $graph -> xaxis -> SetTickLabels($a);
    $graph -> xaxis -> SetFont(FF_SIMSUN);
    $graph -> yscale -> SetGrace(20);

    $p1 new LinePlot($datay);
    $p1 -> mark -> SetType(MARK_FILLEDCIRCLE);
    $p1  -> mark ->SetFillColor('red');
    $p1 -> mark ->SetWidth(4);
    $p1 -> SetColor('blue');
    $p1 -> SetCenter();
    $graph -> Add($p1);
    $graph -> Stroke();
?>


3D饼状图

<?php
    include ("src/jpgraph.php");
    include ("src/jpgraph_pie.php");
    include ("src/jpgraph_pie3d.php");

    $data array(160 ,180 ,203 ,289 ,405 ,500 );
    $graph new PieGraph(540 ,260 ,"auto");
    $graph -> SetShadow();

    $graph -> title -> Set("tit");
    $graph -> title -> SetFont(FF_SIMSUN ,FS_BOLD);
    $graph -> legend -> SetFont(FF_SIMSUN ,FS_NORMAL);

    $p1 new PiePlot3D($data);
    $p1 -> SetLegends(array('11','22','33','44','55','66'));

    $targ array("pie3d_csimex1.php?v=1","pie3d_csimex1.php?v=2","pie3d_csimex1.php?v=3","pie3d_csimex1.php?v=4","pie3d_csimex1.php?v=5","pie3d_csimex1.php?v=6");
    $alts array("val=%d" ,"val=%d" ,"val=%d" ,"val=%d" ,"val=%d" ,"val=%d");
    $p1 -> SetCSIMTargets($targ ,$alts);
    $p1 -> SetCenter(0.4 ,0.5);
    $graph -> Add($p1);
    $graph -> StrokeCSIM();
?>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值